Skip to content

Commit

Permalink
test: 실제 notion DB에 따른 테스트 코드 수정
Browse files Browse the repository at this point in the history
- given 수정
- "역할"로 sort 적용
- plainTestList => names, roles, emails로 분할
  • Loading branch information
coke98 committed Sep 21, 2022
1 parent 6d30834 commit b325912
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 20 deletions.
43 changes: 25 additions & 18 deletions src/test/java/com/gdscpknu/gdscpknu/notion/NotionApiTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import org.jraf.klibnotion.model.page.Page;
import org.jraf.klibnotion.model.pagination.Pagination;
import org.jraf.klibnotion.model.pagination.ResultPage;
import org.jraf.klibnotion.model.property.sort.PropertySort;
import org.junit.jupiter.api.Test;

import java.util.ArrayList;
Expand Down Expand Up @@ -36,17 +37,16 @@ public void getTable() {
);

//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]";
String name = "남우진";
String role = "Lead";
String email = "[email protected]";

//when
ResultPage<Page> simpleQueryResultPage = client.getDatabases().queryDatabase(
Expand All @@ -73,14 +73,16 @@ public void getRowByEmail() {
@Test
void getPlainTexts() {
//given
String name = "가나다";
String role = "Core";
String email = "[email protected]";
String name = "남우진";
String role = "Lead";
String email = "[email protected]";

// "역할" 기준으로 정렬

ResultPage<Page> simpleQueryResultPage = client.getDatabases().queryDatabase(
notionTable.getDATABASE_ID(),
null,
null,
new PropertySort().ascending("역할"),
new Pagination()
);

Expand All @@ -89,7 +91,9 @@ void getPlainTexts() {
* KlibNotion 라이브러리에서 name, email, role 값을 정규식으로 추출하였음
*/
String resultInString = simpleQueryResultPage.results.toString();
List<String> plainTextList = new ArrayList<>();
List<String> names = new ArrayList<>();
List<String> roles = new ArrayList<>();
List<String> emails = new ArrayList<>();
// 문자열 중 "(plainText=" ~ "," 범위(이름, 이메일) OR " "name=" ~ "," 범위(역할) 문자열을 추출
Pattern namePattern = Pattern.compile("(?<=\\(plainText=)(.*?)(?=,)");
Pattern emailPattern = Pattern.compile("(?<=\\bname=이메일, value=)(.*?)(?=\\))");
Expand All @@ -98,20 +102,23 @@ void getPlainTexts() {
Matcher emailMatcher = emailPattern.matcher(resultInString);
Matcher roleMatcher = rolePattern.matcher(resultInString);
while (nameMatcher.find()) {
plainTextList.add(nameMatcher.group());
}
while (emailMatcher.find()) {
plainTextList.add(emailMatcher.group());
names.add(nameMatcher.group());
}
while (roleMatcher.find()) {
plainTextList.add(roleMatcher.group());
roles.add(roleMatcher.group());
}
while (emailMatcher.find()) {
emails.add(emailMatcher.group());
}


//then
assertThat(plainTextList.size()).isEqualTo(notionTable.getMemberNum() * 3);
assertThat(plainTextList.get(0)).isEqualTo(name);
assertThat(plainTextList.get(3)).isEqualTo(email);
assertThat(plainTextList.get(6)).isEqualTo(role);
assertThat(names.size()).isEqualTo(notionTable.getMemberNum());
assertThat(roles.size()).isEqualTo(notionTable.getMemberNum());
assertThat(emails.size()).isEqualTo(notionTable.getMemberNum());
assertThat(names.get(0)).isEqualTo(name);
assertThat(roles.get(0)).isEqualTo(role);
assertThat(emails.get(0)).isEqualTo(email);
}

}
4 changes: 2 additions & 2 deletions src/test/java/com/gdscpknu/gdscpknu/notion/NotionTable.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ public class NotionTable {

private final String TOKEN = "";
private final String DATABASE_ID = "";
private final String tableName = "MEMBER PROFILE";
private final int memberNum = 3;
private final String tableName = "멤버 소개";
private final int memberNum = 39;

public BlockingNotionClient initClient() {
NotionClient notionClient = NotionClient.newInstance(
Expand Down

0 comments on commit b325912

Please sign in to comment.