forked from GDSC-PKNU-Official/GDSC_PKNU_Backend
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Issue GDSC-PKNU-Official#3 test: notion 테이블 가져오기
- Loading branch information
Showing
2 changed files
with
100 additions
and
0 deletions.
There are no files selected for viewing
66 changes: 66 additions & 0 deletions
66
src/test/java/com/gdscpknu/gdscpknu/notion/NotionApiTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
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 | ||
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); | ||
assertThat(simpleQueryResultPage.results.get(0).getPropertyValues().toString().contains(email)).isEqualTo(true); | ||
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
34
src/test/java/com/gdscpknu/gdscpknu/notion/NotionTable.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 = "secret_hN9gav0QDqQMB2neSKszfY6jFHyPxpxYNuiMPNU4HKg"; | ||
private final String DATABASE_ID = "1fea9e9c35984f4ba1cd9c114efc7608"; | ||
private final String tableName = "MEMBER PROFILE"; | ||
private final int memberNum = 3; | ||
|
||
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; | ||
} | ||
} |