Skip to content

Commit

Permalink
test: Make sure that fake date stays in the same month
Browse files Browse the repository at this point in the history
  • Loading branch information
TriPSs committed Dec 1, 2023
1 parent b103072 commit 3ceb52d
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
12 changes: 8 additions & 4 deletions examples/typeorm/e2e/fixtures.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,14 @@ export const refresh = async (connection: Connection): Promise<void> => {
const subTaskRepo = connection.getRepository(SubTaskEntity)
const tagsRepo = connection.getRepository(TagEntity)

const yesterday = new Date()
yesterday.setDate(yesterday.getDate() - 1)

const urgentTag = await tagsRepo.save({ name: 'Urgent', fakeDate: yesterday })
const yesterdayOrTomorrow = new Date()
if (yesterdayOrTomorrow.getDate() === 1) {
yesterdayOrTomorrow.setDate(yesterdayOrTomorrow.getDate() + 1)
} else {
yesterdayOrTomorrow.setDate(yesterdayOrTomorrow.getDate() - 1)
}

const urgentTag = await tagsRepo.save({ name: 'Urgent', fakeDate: yesterdayOrTomorrow })
const homeTag = await tagsRepo.save({ name: 'Home' })
const workTag = await tagsRepo.save({ name: 'Work' })
const questionTag = await tagsRepo.save({ name: 'Question' })
Expand Down
8 changes: 6 additions & 2 deletions examples/typeorm/e2e/tag.resolver.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -443,8 +443,12 @@ describe('TagResolver (typeorm - e2e)', () => {
.then(({ body }) => {
const res: AggregateResponse<TodoItemDTO>[] = body.data.tagAggregate
expect(res).toHaveLength(2)
expect(res[0].sum).toEqual({ id: 1 })
expect(res[1].sum).toEqual({ id: 14 })

// First of the month we switched the days so they stay in the same month
const isFirstOfMonth = new Date().getDate() === 1

expect(res[isFirstOfMonth ? 1 : 0].sum).toEqual({ id: 1 })
expect(res[isFirstOfMonth ? 0 : 1].sum).toEqual({ id: 14 })
}))
})
})
Expand Down

0 comments on commit 3ceb52d

Please sign in to comment.