Skip to content

Commit

Permalink
tests(healthie): add tests for createMetricEntry action (#297)
Browse files Browse the repository at this point in the history
  • Loading branch information
rahulkeerthi authored Jan 10, 2024
1 parent 93f1a85 commit 5c94e9d
Showing 1 changed file with 67 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ describe('createMetricEntry action', () => {
generateTestPayload({
fields: {
userId: '60',
type: 'MetricEntry',
category: 'Weight',
metricStat: 182,
},
Expand All @@ -37,4 +38,70 @@ describe('createMetricEntry action', () => {
expect(onComplete).toBeCalledTimes(1)
expect(onError).toBeCalledTimes(0)
})

test('Should throw an error if the user ID is not provided', async () => {
await createMetricEntry.onActivityCreated(
// @ts-expect-error - userId is missing for testing purposes
generateTestPayload({
fields: {
// userId: '60',
type: 'MetricEntry',
category: 'Weight',
metricStat: 182,
},
settings: {
apiKey: 'apiKey',
apiUrl: 'test-url',
},
}),
onComplete,
onError
)
expect(onComplete).toBeCalledTimes(0)
expect(onError).toBeCalledTimes(1)
})

test('Should throw an error if the category is not provided', async () => {
await createMetricEntry.onActivityCreated(
// @ts-expect-error - category is missing for testing purposes
generateTestPayload({
fields: {
userId: '60',
type: 'MetricEntry',
// category: 'Weight',
metricStat: 182,
},
settings: {
apiKey: 'apiKey',
apiUrl: 'test-url',
},
}),
onComplete,
onError
)
expect(onComplete).toBeCalledTimes(0)
expect(onError).toBeCalledTimes(1)
})

test('Should throw an error if the metricStat is not provided', async () => {
await createMetricEntry.onActivityCreated(
// @ts-expect-error - metricStat is missing for testing purposes
generateTestPayload({
fields: {
userId: '60',
type: 'MetricEntry',
category: 'Weight',
// metricStat: 182,
},
settings: {
apiKey: 'apiKey',
apiUrl: 'test-url',
},
}),
onComplete,
onError
)
expect(onComplete).toBeCalledTimes(0)
expect(onError).toBeCalledTimes(1)
})
})

0 comments on commit 5c94e9d

Please sign in to comment.