Skip to content

Commit

Permalink
Remove unused adapter functions
Browse files Browse the repository at this point in the history
  • Loading branch information
JHWelch committed Aug 12, 2023
1 parent aba4e85 commit f2b35bf
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 154 deletions.
114 changes: 0 additions & 114 deletions __tests__/data/notionAdapter.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,120 +146,6 @@ describe('getWeek', () => {
})
})

describe('getUpcomingWeeks', () => {
describe('when the weeks exist', () => {
beforeEach(() => {
notionMock.mockIsFullPageOrDatabase(true)
notionMock.mockQuery([
NotionMock.mockWeek('weekId1','2021-01-01', 'theme1'),
NotionMock.mockWeek('weekId2','2021-01-08', 'theme2'),
NotionMock.mockWeek('weekId3','2021-01-15', 'theme3'),
])
})

it('should return the weeks', async () => {
const notion = new NotionAdapter()
const weeks = await notion.getUpcomingWeeks()

expect(weeks).toEqual([
{
'id': 'weekId1',
'date': new Date('2021-01-01'),
'isSkipped': false,
'movies': [],
'theme': 'theme1',
}, {
'id': 'weekId2',
'date': new Date('2021-01-08'),
'isSkipped': false,
'movies': [],
'theme': 'theme2',
}, {
'id': 'weekId3',
'date': new Date('2021-01-15'),
'isSkipped': false,
'movies': [],
'theme': 'theme3',
},
])
})

it('should call query with the correct parameters', async () => {
const notion = new NotionAdapter()
await notion.getUpcomingWeeks()

expect(notionMock.query).toHaveBeenCalledWith({
database_id: 'DATABASE_ID',
page_size: 10,
filter: {
property: 'Date',
date: { on_or_after: today() },
},
sorts: [{
property: 'Date',
direction: 'ascending',
}],
})
})
})
})

describe ('getPastWeeks', () => {
beforeEach(() => {
notionMock.mockIsFullPageOrDatabase(true)
notionMock.mockQuery([
NotionMock.mockWeek('weekId3','2021-01-15', 'theme3'),
NotionMock.mockWeek('weekId2','2021-01-08', 'theme2'),
NotionMock.mockWeek('weekId1','2021-01-01', 'theme1'),
])
})

it('should return the weeks', async () => {
const notion = new NotionAdapter()
const weeks = await notion.getPastWeeks()

expect(weeks).toEqual([
{
'id': 'weekId3',
'date': new Date('2021-01-15'),
'isSkipped': false,
'movies': [],
'theme': 'theme3',
}, {
'id': 'weekId2',
'date': new Date('2021-01-08'),
'isSkipped': false,
'movies': [],
'theme': 'theme2',
}, {
'id': 'weekId1',
'date': new Date('2021-01-01'),
'isSkipped': false,
'movies': [],
'theme': 'theme1',
},
])
})

it('should call query with the correct parameters', async () => {
const notion = new NotionAdapter()
await notion.getPastWeeks()

expect(notionMock.query).toHaveBeenCalledWith({
database_id: 'DATABASE_ID',
page_size: 10,
filter: {
property: 'Date',
date: { before: today() },
},
sorts: [{
property: 'Date',
direction: 'descending',
}],
})
})
})

describe('getWeeks', () => {
beforeEach(() => {
notionMock.mockIsFullPageOrDatabase(true)
Expand Down
42 changes: 2 additions & 40 deletions src/data/notionAdapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,42 +62,6 @@ export default class NotionAdapter {
.map(async (record) => await this.recordToWeek(record)))
}

async getUpcomingWeeks (): Promise<Week[]> {
const records = await this.#notion.databases.query({
database_id: this.#databaseId,
page_size: 10,
filter: {
property: 'Date',
date: { on_or_after: today() },
},
sorts: [{
property: 'Date',
direction: 'ascending',
}],
})

return await Promise.all(records.results
.map(async (record) => await this.recordToWeek(record)))
}

async getPastWeeks (): Promise<Week[]> {
const records = await this.#notion.databases.query({
database_id: this.#databaseId,
page_size: 10,
filter: {
property: 'Date',
date: { before: today() },
},
sorts: [{
property: 'Date',
direction: 'descending',
}],
})

return await Promise.all(records.results
.map(async (record) => await this.recordToWeek(record)))
}

async recordToWeek (
record: PageObjectResponse | PartialPageObjectResponse | PartialDatabaseObjectResponse | DatabaseObjectResponse
): Promise<Week> {
Expand All @@ -115,10 +79,8 @@ export default class NotionAdapter {
return Week.fromNotion(record).setMovies(movies)
}

_envVariables (): {
NOTION_TOKEN: string
DATABASE_ID: string
} {
_envVariables (): { NOTION_TOKEN: string, DATABASE_ID: string }
{
const { NOTION_TOKEN, DATABASE_ID } = process.env

if (typeof NOTION_TOKEN !== 'string') {
Expand Down

0 comments on commit f2b35bf

Please sign in to comment.