@furystack/rest-service 6.2.1 → 6.2.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (37) hide show
  1. package/dist/actions/error-action.js +5 -5
  2. package/dist/actions/error-action.js.map +1 -1
  3. package/dist/actions/error-action.spec.js +0 -3
  4. package/dist/actions/error-action.spec.js.map +1 -1
  5. package/dist/endpoint-generators/create-delete-endpoint.spec.js +4 -7
  6. package/dist/endpoint-generators/create-delete-endpoint.spec.js.map +1 -1
  7. package/dist/endpoint-generators/create-get-collection-endpoint.spec.js +15 -14
  8. package/dist/endpoint-generators/create-get-collection-endpoint.spec.js.map +1 -1
  9. package/dist/endpoint-generators/create-get-entity-endpoint.spec.js +12 -18
  10. package/dist/endpoint-generators/create-get-entity-endpoint.spec.js.map +1 -1
  11. package/dist/endpoint-generators/create-patch-endpoint.spec.js +4 -7
  12. package/dist/endpoint-generators/create-patch-endpoint.spec.js.map +1 -1
  13. package/dist/endpoint-generators/create-post-endpoint.spec.js +4 -7
  14. package/dist/endpoint-generators/create-post-endpoint.spec.js.map +1 -1
  15. package/dist/rest-service.integration.spec.js +34 -24
  16. package/dist/rest-service.integration.spec.js.map +1 -1
  17. package/dist/rest.integration.test.js +11 -11
  18. package/dist/rest.integration.test.js.map +1 -1
  19. package/dist/static-server-manager.spec.js +32 -62
  20. package/dist/static-server-manager.spec.js.map +1 -1
  21. package/dist/validate.integration.spec.js +32 -37
  22. package/dist/validate.integration.spec.js.map +1 -1
  23. package/package.json +11 -12
  24. package/src/actions/error-action.spec.ts +0 -3
  25. package/src/actions/error-action.ts +6 -6
  26. package/src/endpoint-generators/create-delete-endpoint.spec.ts +4 -4
  27. package/src/endpoint-generators/create-get-collection-endpoint.spec.ts +17 -11
  28. package/src/endpoint-generators/create-get-entity-endpoint.spec.ts +12 -16
  29. package/src/endpoint-generators/create-patch-endpoint.spec.ts +4 -4
  30. package/src/endpoint-generators/create-post-endpoint.spec.ts +4 -4
  31. package/src/rest-service.integration.spec.ts +36 -29
  32. package/src/rest.integration.test.ts +10 -10
  33. package/src/static-server-manager.spec.ts +32 -39
  34. package/src/validate.integration.spec.ts +31 -36
  35. package/types/actions/error-action.d.ts +0 -2
  36. package/types/actions/error-action.d.ts.map +1 -1
  37. package/types/validate.integration.spec.d.ts.map +1 -1
@@ -2,8 +2,6 @@ import { usingAsync } from '@furystack/utils'
2
2
  import { Injector } from '@furystack/inject'
3
3
  import type { GetEntityEndpoint } from '@furystack/rest'
4
4
  import { serializeToQueryString } from '@furystack/rest'
5
- import type { HTTPError } from 'got'
6
- import got from 'got'
7
5
  import { MockClass, setupContext } from './utils'
8
6
  import { createGetEntityEndpoint } from './create-get-entity-endpoint'
9
7
  import { getDataSetFor } from '@furystack/repository'
@@ -26,8 +24,10 @@ describe('createGetEntityEndpoint', () => {
26
24
  const mockEntity: MockClass = { id: 'mock', value: 'mock' }
27
25
  await getDataSetFor(i, MockClass, 'id').add(i, mockEntity)
28
26
 
29
- const response = await got('http://127.0.0.1:1113/api/mock', { method: 'GET' })
30
- expect(JSON.parse(response.body)).toStrictEqual(mockEntity)
27
+ const response = await fetch('http://127.0.0.1:1113/api/mock', { method: 'GET' })
28
+ expect(response.status).toBe(200)
29
+ const body = await response.json()
30
+ expect(body).toEqual(mockEntity)
31
31
  })
32
32
  })
33
33
 
@@ -47,10 +47,12 @@ describe('createGetEntityEndpoint', () => {
47
47
  const mockEntity: MockClass = { id: 'mock', value: 'mock' }
48
48
  await getDataSetFor(i, MockClass, 'id').add(i, mockEntity)
49
49
 
50
- const response = await got(`http://127.0.0.1:1114/api/mock?${serializeToQueryString({ select: ['id'] })}`, {
50
+ const response = await fetch(`http://127.0.0.1:1114/api/mock?${serializeToQueryString({ select: ['id'] })}`, {
51
51
  method: 'GET',
52
52
  })
53
- expect(JSON.parse(response.body)).toStrictEqual({ id: mockEntity.id })
53
+ expect(response.status).toBe(200)
54
+ const body = await response.json()
55
+ expect(body).toEqual({ id: mockEntity.id })
54
56
  })
55
57
  })
56
58
 
@@ -67,16 +69,10 @@ describe('createGetEntityEndpoint', () => {
67
69
  },
68
70
  },
69
71
  })
70
- await new Promise<void>((resolve, reject) => {
71
- got(`http://127.0.0.1:1115/api/mock`, { method: 'GET' })
72
- .then(() => reject('Should throw'))
73
- .catch((err) => {
74
- const e: HTTPError = err
75
- expect(e.response.statusCode).toBe(404)
76
- expect(JSON.parse(e.response.body as string).message).toBe('Entity not found')
77
- resolve()
78
- })
79
- })
72
+ const result = await fetch(`http://127.0.0.1:1115/api/mock`, { method: 'GET' })
73
+ expect(result.status).toBe(404)
74
+ const body = await result.json()
75
+ expect(body).toEqual({ message: 'Entity not found' })
80
76
  })
81
77
  })
82
78
  })
@@ -2,7 +2,6 @@ import { usingAsync } from '@furystack/utils'
2
2
  import { Injector } from '@furystack/inject'
3
3
  import type { PatchEndpoint } from '@furystack/rest'
4
4
  import { createPatchEndpoint } from './create-patch-endpoint'
5
- import got from 'got'
6
5
  import { MockClass, setupContext } from './utils'
7
6
  import { getDataSetFor } from '@furystack/repository'
8
7
  import { useRestService } from '../helpers'
@@ -26,12 +25,13 @@ describe('createPatchEndpoint', () => {
26
25
  const countBeforeDelete = await getDataSetFor(i, MockClass, 'id').count(i)
27
26
  expect(countBeforeDelete).toBe(1)
28
27
 
29
- const response = await got('http://127.0.0.1:1116/api/mock', {
28
+ const response = await fetch('http://127.0.0.1:1116/api/mock', {
30
29
  method: 'PATCH',
31
30
  body: JSON.stringify({ value: 'updated' }),
32
31
  })
33
- expect(response.statusCode).toBe(200)
34
- expect(response.body).toBe('{}')
32
+ expect(response.status).toBe(200)
33
+ const body = await response.json()
34
+ expect(body).toEqual({})
35
35
  const updated = await getDataSetFor(i, MockClass, 'id').get(i, 'mock')
36
36
  expect(updated?.value).toBe('updated')
37
37
  })
@@ -2,7 +2,6 @@ import { usingAsync } from '@furystack/utils'
2
2
  import { Injector } from '@furystack/inject'
3
3
  import type { PostEndpoint } from '@furystack/rest'
4
4
  import { createPostEndpoint } from './create-post-endpoint'
5
- import got from 'got'
6
5
  import { MockClass, setupContext } from './utils'
7
6
  import { useRestService } from '../helpers'
8
7
  import { getDataSetFor } from '@furystack/repository'
@@ -22,12 +21,13 @@ describe('createPostEndpoint', () => {
22
21
  },
23
22
  })
24
23
  const entityToPost = { id: 'mock', value: 'posted' }
25
- const response = await got('http://127.0.0.1:1117/api/mock', {
24
+ const response = await fetch('http://127.0.0.1:1117/api/mock', {
26
25
  method: 'POST',
27
26
  body: JSON.stringify(entityToPost),
28
27
  })
29
- expect(response.statusCode).toBe(201)
30
- expect(JSON.parse(response.body)).toStrictEqual(entityToPost)
28
+ expect(response.status).toBe(201)
29
+ const body = await response.json()
30
+ expect(body).toEqual(entityToPost)
31
31
  const posted = await getDataSetFor(i, MockClass, 'id').get(i, entityToPost.id)
32
32
  expect(posted?.value).toBe('posted')
33
33
  })
@@ -5,7 +5,6 @@ import { GetCurrentUser, IsAuthenticated, LoginAction, LogoutAction } from './ac
5
5
  import type { RestApi } from '@furystack/rest'
6
6
  import { User, InMemoryStore, addStore } from '@furystack/core'
7
7
  import { DefaultSession } from './models/default-session'
8
- import got from 'got'
9
8
  import { JsonResult } from './request-action-implementation'
10
9
  import { useHttpAuthentication, useRestService } from './helpers'
11
10
 
@@ -81,87 +80,95 @@ describe('@furystack/rest-service inregration tests', () => {
81
80
  it('Should respond with 404 when a route is not found', async () => {
82
81
  await usingAsync(new Injector(), async (i) => {
83
82
  await prepareInjector(i)
84
- await expect(got(PathHelper.joinPaths(apiUrl, 'some-route-that-does-not-exists'))).rejects.toThrow(
85
- 'Response code 404 (Not Found)',
86
- )
83
+ const result = await fetch(PathHelper.joinPaths(apiUrl, 'some-route-that-does-not-exists'))
84
+ expect(result.ok).toBe(false)
85
+ expect(result.status).toBe(404)
86
+ const responseText = await result.json()
87
+ expect(responseText).toEqual({ error: 'Content not found' })
87
88
  })
88
89
  })
89
90
 
90
91
  it('Should respond with 401 for unauthorized request errors', async () => {
91
92
  await usingAsync(new Injector(), async (i) => {
92
93
  await prepareInjector(i)
93
- await expect(got(PathHelper.joinPaths(apiUrl, 'currentUser'), { retry: 0 })).rejects.toThrow(
94
- 'Response code 401 (Unauthorized)',
95
- )
94
+ const result = await fetch(PathHelper.joinPaths(apiUrl, 'currentUser'))
95
+ expect(result.ok).toBe(false)
96
+ expect(result.status).toBe(401)
97
+ const responseText = await result.json()
98
+ expect(responseText).toEqual({ error: 'unauthorized' })
96
99
  })
97
100
  })
98
101
 
99
102
  it('Should respond with 401 for unauthorized request errors', async () => {
100
103
  await usingAsync(new Injector(), async (i) => {
101
104
  await prepareInjector(i)
102
- await expect(got(PathHelper.joinPaths(apiUrl, 'currentUser'), { retry: 0 })).rejects.toThrow(
103
- 'Response code 401 (Unauthorized)',
104
- )
105
+ const result = await fetch(PathHelper.joinPaths(apiUrl, 'currentUser'))
106
+ expect(result.ok).toBe(false)
107
+ expect(result.status).toBe(401)
108
+ const responseText = await result.json()
109
+ expect(responseText).toEqual({ error: 'unauthorized' })
105
110
  })
106
111
  })
107
112
 
108
113
  it('Should respond with the correct result body', async () => {
109
114
  await usingAsync(new Injector(), async (i) => {
110
115
  await prepareInjector(i)
111
- const response = await got(PathHelper.joinPaths(apiUrl, 'isAuthenticated'), { retry: 0 })
112
- expect(response.statusCode).toBe(200)
113
- expect(JSON.parse(response.body)).toStrictEqual({ isAuthenticated: false })
116
+ const response = await fetch(PathHelper.joinPaths(apiUrl, 'isAuthenticated'))
117
+ expect(response.status).toBe(200)
118
+ const result = await response.json()
119
+ expect(result).toEqual({ isAuthenticated: false })
114
120
  })
115
121
  })
116
122
 
117
123
  it('Should be able to read query parameters', async () => {
118
124
  await usingAsync(new Injector(), async (i) => {
119
125
  await prepareInjector(i)
120
- const response = await got(PathHelper.joinPaths(apiUrl, 'testQuery?param1=foo'), { retry: 0 })
121
- expect(response.statusCode).toBe(200)
122
- expect(JSON.parse(response.body)).toStrictEqual({ param1Value: 'foo' })
126
+ const response = await fetch(PathHelper.joinPaths(apiUrl, 'testQuery?param1=foo'))
127
+ expect(response.status).toBe(200)
128
+ const result = await response.json()
129
+ expect(result).toEqual({ param1Value: 'foo' })
123
130
  })
124
131
  })
125
132
 
126
133
  it('Should be able to read url parameters', async () => {
127
134
  await usingAsync(new Injector(), async (i) => {
128
135
  await prepareInjector(i)
129
- const response = await got(PathHelper.joinPaths(apiUrl, 'testUrlParams/bar'), { retry: 0 })
130
- expect(response.statusCode).toBe(200)
131
- expect(JSON.parse(response.body)).toStrictEqual({ urlParamValue: 'bar' })
136
+ const response = await fetch(PathHelper.joinPaths(apiUrl, 'testUrlParams/bar'))
137
+ expect(response.status).toBe(200)
138
+ const result = await response.json()
139
+ expect(result).toEqual({ urlParamValue: 'bar' })
132
140
  })
133
141
  })
134
142
 
135
143
  it('Should be able to read post body', async () => {
136
144
  await usingAsync(new Injector(), async (i) => {
137
145
  await prepareInjector(i)
138
- const response = await got(PathHelper.joinPaths(apiUrl, 'testPostBody'), {
146
+ const response = await fetch(PathHelper.joinPaths(apiUrl, 'testPostBody'), {
139
147
  method: 'POST',
140
148
  body: JSON.stringify({ value: 'baz' }),
141
- retry: 0,
142
149
  })
143
- expect(response.statusCode).toBe(200)
144
- expect(JSON.parse(response.body)).toStrictEqual({ bodyValue: 'baz', body2Value: 'baz' })
150
+ expect(response.status).toBe(200)
151
+ const result = await response.json()
152
+ expect(result).toEqual({ bodyValue: 'baz', body2Value: 'baz' })
145
153
  })
146
154
  })
147
155
 
148
156
  it('Should respond with OK to OPTIONS requests', async () => {
149
157
  await usingAsync(new Injector(), async (i) => {
150
158
  await prepareInjector(i)
151
- const response = await got(PathHelper.joinPaths(apiUrl, 'testPostBody'), {
159
+ const response = await fetch(PathHelper.joinPaths(apiUrl, 'testPostBody'), {
152
160
  method: 'OPTIONS',
153
- retry: 0,
154
161
  })
155
- expect(response.statusCode).toBe(200)
162
+ expect(response.status).toBe(200)
156
163
  })
157
164
  })
158
165
 
159
166
  it('Should reject requests outside of the API Root', async () => {
160
167
  await usingAsync(new Injector(), async (i) => {
161
168
  await prepareInjector(i)
162
- await expect(
163
- got(PathHelper.joinPaths(`http://${hostName}:${port}`, 'not-my-api-root'), { retry: 0 }),
164
- ).rejects.toThrowError('socket hang up')
169
+ await expect(fetch(PathHelper.joinPaths(`http://${hostName}:${port}`, 'not-my-api-root'))).rejects.toThrowError(
170
+ 'fetch failed',
171
+ )
165
172
  })
166
173
  })
167
174
  })
@@ -1,6 +1,6 @@
1
1
  import { Injector } from '@furystack/inject'
2
2
  import type { RestApi } from '@furystack/rest'
3
- import { createClient } from '@furystack/rest-client-got'
3
+ import { createClient } from '@furystack/rest-client-fetch'
4
4
  import { usingAsync } from '@furystack/utils'
5
5
  import { JsonResult } from './request-action-implementation'
6
6
  import './helpers'
@@ -52,15 +52,15 @@ const createEchoApiServer = async () => {
52
52
  }
53
53
  }
54
54
 
55
- describe('REST Integration tests with GOT client', () => {
55
+ describe('REST Integration tests with FETCH client', () => {
56
56
  it('Should execute a single parameterless GET query', async () => {
57
57
  await usingAsync(await createEchoApiServer(), async ({ client }) => {
58
58
  const result = await client({
59
59
  method: 'GET',
60
60
  action: '/plain',
61
61
  })
62
- expect(result.response.statusCode).toBe(200)
63
- expect(result.getJson()).toStrictEqual({})
62
+ expect(result.response.status).toBe(200)
63
+ expect(result.result).toEqual({})
64
64
  })
65
65
  })
66
66
 
@@ -74,8 +74,8 @@ describe('REST Integration tests with GOT client', () => {
74
74
  value,
75
75
  },
76
76
  })
77
- expect(result.response.statusCode).toBe(200)
78
- expect(result.getJson().headers.value).toStrictEqual(value)
77
+ expect(result.response.status).toBe(200)
78
+ expect(result.result.headers.value).toEqual(value)
79
79
  })
80
80
  })
81
81
 
@@ -91,8 +91,8 @@ describe('REST Integration tests with GOT client', () => {
91
91
  },
92
92
  },
93
93
  })
94
- expect(result.response.statusCode).toBe(200)
95
- expect(result.getJson().query.someObject.foo).toStrictEqual(value)
94
+ expect(result.response.status).toBe(200)
95
+ expect(result.result.query.someObject.foo).toEqual(value)
96
96
  })
97
97
  })
98
98
 
@@ -106,8 +106,8 @@ describe('REST Integration tests with GOT client', () => {
106
106
  id: value,
107
107
  },
108
108
  })
109
- expect(result.response.statusCode).toBe(200)
110
- expect(result.getJson().url.id).toEqual(value)
109
+ expect(result.response.status).toBe(200)
110
+ expect(result.result.url.id).toEqual(value)
111
111
  })
112
112
  })
113
113
  })
@@ -1,6 +1,5 @@
1
1
  import { Injector } from '@furystack/inject'
2
2
  import { sleepAsync, usingAsync } from '@furystack/utils'
3
- import got, { RequestError } from 'got'
4
3
  import { ServerManager } from './server-manager'
5
4
  import { StaticServerManager } from './static-server-manager'
6
5
 
@@ -34,16 +33,12 @@ describe('StaticServerManager', () => {
34
33
  port,
35
34
  })
36
35
 
37
- try {
38
- await got.get(`http://localhost:${port}/not-found.html`)
39
- } catch (error) {
40
- expect(error).toBeInstanceOf(RequestError)
41
- const requestError: RequestError = error as RequestError
42
-
43
- expect(requestError.response?.statusCode).toBe(404)
44
- expect(requestError.response?.headers['content-type']).toBe('text/plain')
45
- expect(requestError.response?.body).toBe('Not found')
46
- }
36
+ const result = await fetch(`http://localhost:${port}/not-found.html`)
37
+ expect(result.ok).toBe(false)
38
+ expect(result.status).toBe(404)
39
+ expect(result?.headers.get('content-type')).toBe('text/plain')
40
+ const body = await result.text()
41
+ expect(body).toBe('Not found')
47
42
  })
48
43
  })
49
44
 
@@ -62,10 +57,10 @@ describe('StaticServerManager', () => {
62
57
  },
63
58
  })
64
59
 
65
- const result = await got.get(`http://localhost:${port}/not-found.html`)
60
+ const result = await fetch(`http://localhost:${port}/not-found.html`)
66
61
 
67
- expect(result.headers['content-type']).toBe('application/json')
68
- expect(result.headers['custom-header']).toBe('custom-value')
62
+ expect(result.headers.get('content-type')).toBe('application/json')
63
+ expect(result.headers.get('custom-header')).toBe('custom-value')
69
64
  })
70
65
  })
71
66
 
@@ -84,10 +79,10 @@ describe('StaticServerManager', () => {
84
79
  },
85
80
  })
86
81
 
87
- const result = await got.get(`http://localhost:${port}`)
82
+ const result = await fetch(`http://localhost:${port}`)
88
83
 
89
- expect(result.headers['content-type']).toBe('application/json')
90
- expect(result.headers['custom-header']).toBe('custom-value')
84
+ expect(result.headers.get('content-type')).toBe('application/json')
85
+ expect(result.headers.get('custom-header')).toBe('custom-value')
91
86
  })
92
87
  })
93
88
 
@@ -105,10 +100,10 @@ describe('StaticServerManager', () => {
105
100
  },
106
101
  })
107
102
 
108
- const result = await got.get(`http://localhost:${port}/README.md`)
103
+ const result = await fetch(`http://localhost:${port}/README.md`)
109
104
 
110
- expect(result.headers['content-type']).toBe('text/markdown')
111
- expect(result.headers['custom-header']).toBe('custom-value')
105
+ expect(result.headers.get('content-type')).toBe('text/markdown')
106
+ expect(result.headers.get('custom-header')).toBe('custom-value')
112
107
  })
113
108
  })
114
109
 
@@ -123,9 +118,9 @@ describe('StaticServerManager', () => {
123
118
  port,
124
119
  })
125
120
 
126
- const result = await got.get(`http://localhost:${port}/packages/utils/README.md`)
121
+ const result = await fetch(`http://localhost:${port}/packages/utils/README.md`)
127
122
 
128
- expect(result.headers['content-type']).toBe('text/markdown')
123
+ expect(result.headers.get('content-type')).toBe('text/markdown')
129
124
  })
130
125
  })
131
126
  })
@@ -146,7 +141,9 @@ describe('StaticServerManager', () => {
146
141
 
147
142
  server.apis[0].onRequest = jest.fn()
148
143
 
149
- got.get(`http://localhost:${port}/bundleToAnotherFolder/not-found.html`)
144
+ fetch(`http://localhost:${port}/bundleToAnotherFolder/not-found.html`).catch(() => {
145
+ /** should fall, ignore */
146
+ })
150
147
 
151
148
  await sleepAsync(100)
152
149
 
@@ -165,16 +162,12 @@ describe('StaticServerManager', () => {
165
162
  port,
166
163
  })
167
164
 
168
- try {
169
- await got.get(`http://localhost:${port}/bundle/not-found.html`)
170
- } catch (error) {
171
- expect(error).toBeInstanceOf(RequestError)
172
- const requestError: RequestError = error as RequestError
173
-
174
- expect(requestError.response?.statusCode).toBe(404)
175
- expect(requestError.response?.headers['content-type']).toBe('text/plain')
176
- expect(requestError.response?.body).toBe('Not found')
177
- }
165
+ const result = await fetch(`http://localhost:${port}/bundle/not-found.html`)
166
+ expect(result.ok).toBe(false)
167
+ expect(result.status).toBe(404)
168
+ expect(result.headers.get('content-type')).toBe('text/plain')
169
+ const body = await result.text()
170
+ expect(body).toBe('Not found')
178
171
  })
179
172
  })
180
173
 
@@ -190,9 +183,9 @@ describe('StaticServerManager', () => {
190
183
  port,
191
184
  })
192
185
 
193
- const result = await got.get(`http://localhost:${port}/bundle/not-found.html`)
186
+ const result = await fetch(`http://localhost:${port}/bundle/not-found.html`)
194
187
 
195
- expect(result.headers['content-type']).toBe('application/json')
188
+ expect(result.headers.get('content-type')).toBe('application/json')
196
189
  })
197
190
  })
198
191
 
@@ -207,9 +200,9 @@ describe('StaticServerManager', () => {
207
200
  port,
208
201
  })
209
202
 
210
- const result = await got.get(`http://localhost:${port}/README.md`)
203
+ const result = await fetch(`http://localhost:${port}/README.md`)
211
204
 
212
- expect(result.headers['content-type']).toBe('text/markdown')
205
+ expect(result.headers.get('content-type')).toBe('text/markdown')
213
206
  })
214
207
  })
215
208
 
@@ -224,9 +217,9 @@ describe('StaticServerManager', () => {
224
217
  port,
225
218
  })
226
219
 
227
- const result = await got.get(`http://localhost:${port}/packages/utils/README.md`)
220
+ const result = await fetch(`http://localhost:${port}/packages/utils/README.md`)
228
221
 
229
- expect(result.headers['content-type']).toBe('text/markdown')
222
+ expect(result.headers.get('content-type')).toBe('text/markdown')
230
223
  })
231
224
  })
232
225
  })
@@ -1,7 +1,6 @@
1
1
  import { Injector } from '@furystack/inject'
2
- import { createClient } from '@furystack/rest-client-got'
2
+ import { createClient, ResponseError } from '@furystack/rest-client-fetch'
3
3
  import { usingAsync } from '@furystack/utils'
4
- import { RequestError } from 'got/dist/source'
5
4
  import { JsonResult } from './request-action-implementation'
6
5
  import { Validate } from './validate'
7
6
  import './helpers'
@@ -75,10 +74,10 @@ describe('Validation integration tests', () => {
75
74
  query: undefined as any,
76
75
  })
77
76
  } catch (error) {
78
- if (error instanceof RequestError) {
79
- expect(error.message).toBe('Response code 400 (Bad Request)')
80
- expect(error.response?.statusCode).toBe(400)
81
- const responseJson = JSON.parse(error.response?.body as string)
77
+ if (error instanceof ResponseError) {
78
+ expect(error.message).toBe('Bad Request')
79
+ expect(error.response?.status).toBe(400)
80
+ const responseJson = await error.response.json()
82
81
  expect(responseJson.errors[0].params.missingProperty).toEqual('foo')
83
82
  expect(responseJson.errors[1].params.missingProperty).toEqual('bar')
84
83
  expect(responseJson.errors[2].params.missingProperty).toEqual('baz')
@@ -96,10 +95,10 @@ describe('Validation integration tests', () => {
96
95
  url: undefined as any,
97
96
  })
98
97
  } catch (error) {
99
- if (error instanceof RequestError) {
100
- expect(error.message).toBe('Response code 400 (Bad Request)')
101
- expect(error.response?.statusCode).toBe(400)
102
- const responseJson = JSON.parse(error.response?.body as string)
98
+ if (error instanceof ResponseError) {
99
+ expect(error.message).toBe('Bad Request')
100
+ expect(error.response?.status).toBe(400)
101
+ const responseJson = await error.response.json()
103
102
  expect(responseJson.errors[0].params.type).toEqual('number')
104
103
  expect(responseJson.errors[0].instancePath).toEqual('/url/id')
105
104
  }
@@ -116,10 +115,10 @@ describe('Validation integration tests', () => {
116
115
  headers: undefined as any,
117
116
  })
118
117
  } catch (error) {
119
- if (error instanceof RequestError) {
120
- expect(error.message).toBe('Response code 400 (Bad Request)')
121
- expect(error.response?.statusCode).toBe(400)
122
- const responseJson = JSON.parse(error.response?.body as string)
118
+ if (error instanceof ResponseError) {
119
+ expect(error.message).toBe('Bad Request')
120
+ expect(error.response?.status).toBe(400)
121
+ const responseJson = await error.response.json()
123
122
  expect(
124
123
  responseJson.errors.find((e: any) => e.keyword === 'required' && e.message.includes('foo')),
125
124
  ).toBeDefined()
@@ -137,10 +136,10 @@ describe('Validation integration tests', () => {
137
136
  body: undefined as any,
138
137
  })
139
138
  } catch (error) {
140
- if (error instanceof RequestError) {
141
- expect(error.message).toBe('Response code 400 (Bad Request)')
142
- expect(error.response?.statusCode).toBe(400)
143
- const responseJson = JSON.parse(error.response?.body as string)
139
+ if (error instanceof ResponseError) {
140
+ expect(error.message).toBe('Bad Request')
141
+ expect(error.response?.status).toBe(400)
142
+ const responseJson = await error.response.json()
144
143
  expect(responseJson.errors[0].params.missingProperty).toEqual('body')
145
144
  }
146
145
  }
@@ -160,11 +159,10 @@ describe('Validation integration tests', () => {
160
159
  baz: false,
161
160
  },
162
161
  })
163
- expect(result.response.statusCode).toBe(200)
164
- const responseJson = result.getJson()
165
- expect(responseJson.foo).toBe('foo')
166
- expect(responseJson.bar).toBe(2)
167
- expect(responseJson.baz).toBe(false)
162
+ expect(result.response.status).toBe(200)
163
+ expect(result.result.foo).toBe('foo')
164
+ expect(result.result.bar).toBe(2)
165
+ expect(result.result.baz).toBe(false)
168
166
  })
169
167
  })
170
168
  it('Should validate url', async () => {
@@ -174,9 +172,8 @@ describe('Validation integration tests', () => {
174
172
  action: '/validate-url/:id',
175
173
  url: { id: 3 },
176
174
  })
177
- expect(result.response.statusCode).toBe(200)
178
- const responseJson = result.getJson()
179
- expect(responseJson.id).toBe(3)
175
+ expect(result.response.status).toBe(200)
176
+ expect(result.result.id).toBe(3)
180
177
  })
181
178
  })
182
179
  it('Should validate headers', async () => {
@@ -190,11 +187,10 @@ describe('Validation integration tests', () => {
190
187
  baz: true,
191
188
  },
192
189
  })
193
- expect(result.response.statusCode).toBe(200)
194
- const responseJson = result.getJson()
195
- expect(responseJson.foo).toBe('foo')
196
- expect(responseJson.bar).toBe(42)
197
- expect(responseJson.baz).toBe(true)
190
+ expect(result.response.status).toBe(200)
191
+ expect(result.result.foo).toBe('foo')
192
+ expect(result.result.bar).toBe(42)
193
+ expect(result.result.baz).toBe(true)
198
194
  })
199
195
  })
200
196
  it('Should validate body', async () => {
@@ -209,11 +205,10 @@ describe('Validation integration tests', () => {
209
205
  },
210
206
  })
211
207
 
212
- expect(result.response.statusCode).toBe(200)
213
- const responseJson = result.getJson()
214
- expect(responseJson.foo).toBe('foo')
215
- expect(responseJson.bar).toBe(42)
216
- expect(responseJson.baz).toBe(true)
208
+ expect(result.response.status).toBe(200)
209
+ expect(result.result.foo).toBe('foo')
210
+ expect(result.result.bar).toBe(42)
211
+ expect(result.result.baz).toBe(true)
217
212
  })
218
213
  })
219
214
  })
@@ -7,8 +7,6 @@ export declare const ErrorAction: RequestAction<{
7
7
  body: unknown;
8
8
  result: {
9
9
  message: string;
10
- url?: string;
11
- stack?: string;
12
10
  };
13
11
  }>;
14
12
  //# sourceMappingURL=error-action.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"error-action.d.ts","sourceRoot":"","sources":["../../src/actions/error-action.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,kCAAkC,CAAA;AAIrE;;;GAGG;AAEH,eAAO,MAAM,WAAW,EAAE,aAAa,CAAC;IACtC,IAAI,EAAE,OAAO,CAAA;IACb,MAAM,EAAE;QAAE,OAAO,EAAE,MAAM,CAAC;QAAC,GAAG,CAAC,EAAE,MAAM,CAAC;QAAC,KAAK,CAAC,EAAE,MAAM,CAAA;KAAE,CAAA;CAC1D,CAoBA,CAAA"}
1
+ {"version":3,"file":"error-action.d.ts","sourceRoot":"","sources":["../../src/actions/error-action.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,kCAAkC,CAAA;AAIrE;;;GAGG;AAEH,eAAO,MAAM,WAAW,EAAE,aAAa,CAAC;IACtC,IAAI,EAAE,OAAO,CAAA;IACb,MAAM,EAAE;QAAE,OAAO,EAAE,MAAM,CAAA;KAAE,CAAA;CAC5B,CAoBA,CAAA"}
@@ -1 +1 @@
1
- {"version":3,"file":"validate.integration.spec.d.ts","sourceRoot":"","sources":["../src/validate.integration.spec.ts"],"names":[],"mappings":"AAMA,OAAO,WAAW,CAAA"}
1
+ {"version":3,"file":"validate.integration.spec.d.ts","sourceRoot":"","sources":["../src/validate.integration.spec.ts"],"names":[],"mappings":"AAKA,OAAO,WAAW,CAAA"}