Skip to content

Commit ec7e80b

Browse files
committed
add missing test
1 parent a044a4f commit ec7e80b

2 files changed

Lines changed: 54 additions & 1 deletion

File tree

packages/lib-ts/src/queries/ApiQuery.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,6 @@ export class ApiQueryResponse extends QueryResponseBase {
3131
}
3232

3333
toResult(): Result<string, string> {
34-
return this.buildResult<string>(this.data, 'Unknown error getting api call')
34+
return this.buildResult<string>(this.data, 'Unknown error getting API response')
3535
}
3636
}
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
import { ApiQueryResponse } from '../../src/queries'
2+
3+
describe('ApiQueryResponse', () => {
4+
describe('toResult', () => {
5+
describe('when response is successful', () => {
6+
describe('when data is provided', () => {
7+
it('should return result with data', () => {
8+
const responseData = '{"test": true}'
9+
const response = new ApiQueryResponse('true', responseData, '')
10+
const result = response.toResult()
11+
12+
expect(result.isOk).toBe(true)
13+
const data = result.unwrap()
14+
expect(data).toBe(responseData)
15+
})
16+
})
17+
18+
describe('when data is empty', () => {
19+
it('should return empty string', () => {
20+
const response = new ApiQueryResponse('true', '', '')
21+
const result = response.toResult()
22+
23+
expect(result.isOk).toBe(true)
24+
const data = result.unwrap()
25+
expect(data).toBe('')
26+
})
27+
})
28+
})
29+
30+
describe('when response is not successful', () => {
31+
describe('when error message is provided', () => {
32+
it('should return error with provided message', () => {
33+
const errorMessage = 'Something went wrong'
34+
const response = new ApiQueryResponse('false', '', errorMessage)
35+
const result = response.toResult()
36+
37+
expect(result.isError).toBe(true)
38+
expect(result.error).toBe(errorMessage)
39+
})
40+
})
41+
42+
describe('when error message is not provided', () => {
43+
it('should return default error message', () => {
44+
const response = new ApiQueryResponse('false', '', '')
45+
const result = response.toResult()
46+
47+
expect(result.isError).toBe(true)
48+
expect(result.error).toBe('Unknown error getting API response')
49+
})
50+
})
51+
})
52+
})
53+
})

0 commit comments

Comments
 (0)