Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/#3 노션 API 테스트 #4

Merged
merged 6 commits into from
Sep 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ bin/
out/
!**/src/main/**/out/
!**/src/test/**/out/
/src/main/java/resources/application.yml

### NetBeans ###
/nbproject/private/
Expand Down
1 change: 1 addition & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ repositories {
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'org.jraf:klibnotion:1.11.0'
compileOnly 'org.projectlombok:lombok'
runtimeOnly 'mysql:mysql-connector-java'
annotationProcessor 'org.projectlombok:lombok'
Expand Down
68 changes: 68 additions & 0 deletions src/test/java/com/gdscpknu/gdscpknu/notion/NotionApiTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
package com.gdscpknu.gdscpknu.notion;

import org.jraf.klibnotion.client.blocking.BlockingNotionClient;
import org.jraf.klibnotion.model.database.Database;
import org.jraf.klibnotion.model.database.query.DatabaseQuery;
import org.jraf.klibnotion.model.database.query.filter.DatabaseQueryPredicate;
import org.jraf.klibnotion.model.database.query.filter.DatabaseQueryPropertyFilter;
import org.jraf.klibnotion.model.page.Page;
import org.jraf.klibnotion.model.pagination.Pagination;
import org.jraf.klibnotion.model.pagination.ResultPage;
import org.junit.jupiter.api.Test;

import static org.assertj.core.api.Assertions.*;

public class NotionApiTest {

private final NotionTable notionTable = new NotionTable();
private final BlockingNotionClient client = notionTable.initClient();

@Test
public void getTable() {
//given

//when
Database database = client.getDatabases().getDatabase(notionTable.getDATABASE_ID());
ResultPage<Page> simpleQueryResultPage = client.getDatabases().queryDatabase(
notionTable.getDATABASE_ID(),
null,
null,
new Pagination()
);

//then
// System.out.println("simpleQueryResultPage = " + simpleQueryResultPage.results);
assertThat(database.getTitle().getPlainText()).isEqualTo(notionTable.getTableName());
assertThat(simpleQueryResultPage.results.size()).isEqualTo(notionTable.getMemberNum());
}

@Test
public void getRowByEmail() {
//given
String name = "가나다";
String role = "Core";
String email = "[email protected]";

//when
ResultPage<Page> simpleQueryResultPage = client.getDatabases().queryDatabase(
notionTable.getDATABASE_ID(),
new DatabaseQuery()
.any(
new DatabaseQueryPropertyFilter.Text(
"이메일",
new DatabaseQueryPredicate.Text.Equals(email)
)
),
null,
new Pagination()
);

//then
assertThat(simpleQueryResultPage.results.size()).isEqualTo(1);
// System.out.println("simpleQueryResultPage = " + simpleQueryResultPage.results.get(0).getPropertyValues());
assertThat(simpleQueryResultPage.results.get(0).getPropertyValues().toString().contains(email)).isEqualTo(true);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

equals 써서 바로 string 비교할 수도 있지 않나요? 호옥시 contains.equals(true)로 한 이유가 있을까요?? 저도 잘 몰라서 질문 드려용

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

simpleQueryResultPage.results.get(0).getPropertyValues()
-> 이렇게 하면 사용자 이름, 이메일, 역할에 관한 정보가 들어가 있긴 한데
bold=false, italic=false, strikethrough=false, underline=false 이런 정보들도 같이 나와서 contains 사용했습니다.

simpleQueryResultPage.results.get(0).getPropertyValues().get(0).getValue()
-> 하면 이메일 정보만 따로 나오긴 하는데 여기에도 다른 정보들도 같이 나와서 일단 저렇게 작성해뒀습니다.

  • 원하는 email, name, role 값만 꺼내려는데 잘 안돼서 contains 사용했는데 고칠 필요가 있을 것 같습니다!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

실제 사용하는 과정에서는 파싱해서 email, name, role만 따로 가져올 필요가 있겠네요.
답변 감사합니다!

assertThat(simpleQueryResultPage.results.get(0).getPropertyValues().toString().contains(role)).isEqualTo(true);
assertThat(simpleQueryResultPage.results.get(0).getPropertyValues().toString().contains(name)).isEqualTo(true);
}

}
34 changes: 34 additions & 0 deletions src/test/java/com/gdscpknu/gdscpknu/notion/NotionTable.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package com.gdscpknu.gdscpknu.notion;

import org.jraf.klibnotion.client.*;
import org.jraf.klibnotion.client.blocking.BlockingNotionClient;
import org.jraf.klibnotion.client.blocking.BlockingNotionClientUtils;

public class NotionTable {

private final String TOKEN = "";
private final String DATABASE_ID = "";
private final String tableName = "MEMBER PROFILE";
private final int memberNum = 3;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

memberNum은 회원 수를 말하는 거죠?? 테스트 용으로 임의로 3명으로 지정해 놓은 변수로 이해하면 될까요?

Copy link
Collaborator Author

@dmswjdchl dmswjdchl Sep 17, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

네넵 맞습니다!


public BlockingNotionClient initClient() {
NotionClient notionClient = NotionClient.newInstance(
new ClientConfiguration(
new Authentication(TOKEN)
)
);
return BlockingNotionClientUtils.asBlockingNotionClient(notionClient);
}

public String getDATABASE_ID() {
return DATABASE_ID;
}

public String getTableName() {
return tableName;
}

public int getMemberNum() {
return memberNum;
}
}