Skip to content

Commit

Permalink
fix(events): XXX-0 use events api rather than reports for getAll
Browse files Browse the repository at this point in the history
  • Loading branch information
noticeeverything committed May 5, 2022
1 parent 787616e commit 8bb92df
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 19 deletions.
4 changes: 2 additions & 2 deletions src/lib/events/events.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ describe('Events', () => {
})

it('finds all events', async () => {
jest.spyOn(axiosMock, 'post').mockResolvedValue({ data: [] })
jest.spyOn(axiosMock, 'get').mockResolvedValue({ data: [] })
await expect(events.getAll()).resolves.toEqual([])
})

Expand All @@ -29,7 +29,7 @@ describe('Events', () => {
{ id: 3, date: new Date('01/03/2021').toISOString() },
{ id: 4, date: new Date('02/01/2021').toISOString() },
]
jest.spyOn(axiosMock, 'post').mockResolvedValue({ data })
jest.spyOn(axiosMock, 'get').mockResolvedValue({ data })
data.pop()
await expect(events.getAll('2021/01/01', '2021/01/31')).resolves.toEqual(data)
})
Expand Down
23 changes: 6 additions & 17 deletions src/lib/events/events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,23 +13,12 @@ export class Events {
async getAll(start?: DateString, end?: DateString): Promise<TimelyEvent[]> {
// Ensure given date range conforms to ISO string format
const [startDate, endDate] = [start, end].map((s) => (s ? this.ensureISOFormat(s) : null))
const { data } = await this.http.post(`/${this.config.accountId}/reports/filter.json`, {
// TODO: Are all properties required?
project_ids: '',
user_ids: '',
team_ids: '',
label_ids: '',
since: startDate,
until: endDate,
scope: 'events',
limit: 9999,
page: 1,
select: 'all',
sort: 'day',
order: 'desc',
published: true,
})

const params = {} as { since: string; upto: string }
if (startDate && endDate) {
params.since = startDate
params.upto = endDate
}
const { data } = await this.http.get(`/${this.config.accountId}/events`, { params })
return data
}

Expand Down

0 comments on commit 8bb92df

Please sign in to comment.