@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.
- package/dist/actions/error-action.js +5 -5
- package/dist/actions/error-action.js.map +1 -1
- package/dist/actions/error-action.spec.js +0 -3
- package/dist/actions/error-action.spec.js.map +1 -1
- package/dist/endpoint-generators/create-delete-endpoint.spec.js +4 -7
- package/dist/endpoint-generators/create-delete-endpoint.spec.js.map +1 -1
- package/dist/endpoint-generators/create-get-collection-endpoint.spec.js +15 -14
- package/dist/endpoint-generators/create-get-collection-endpoint.spec.js.map +1 -1
- package/dist/endpoint-generators/create-get-entity-endpoint.spec.js +12 -18
- package/dist/endpoint-generators/create-get-entity-endpoint.spec.js.map +1 -1
- package/dist/endpoint-generators/create-patch-endpoint.spec.js +4 -7
- package/dist/endpoint-generators/create-patch-endpoint.spec.js.map +1 -1
- package/dist/endpoint-generators/create-post-endpoint.spec.js +4 -7
- package/dist/endpoint-generators/create-post-endpoint.spec.js.map +1 -1
- package/dist/rest-service.integration.spec.js +34 -24
- package/dist/rest-service.integration.spec.js.map +1 -1
- package/dist/rest.integration.test.js +11 -11
- package/dist/rest.integration.test.js.map +1 -1
- package/dist/static-server-manager.spec.js +32 -62
- package/dist/static-server-manager.spec.js.map +1 -1
- package/dist/validate.integration.spec.js +32 -37
- package/dist/validate.integration.spec.js.map +1 -1
- package/package.json +11 -12
- package/src/actions/error-action.spec.ts +0 -3
- package/src/actions/error-action.ts +6 -6
- package/src/endpoint-generators/create-delete-endpoint.spec.ts +4 -4
- package/src/endpoint-generators/create-get-collection-endpoint.spec.ts +17 -11
- package/src/endpoint-generators/create-get-entity-endpoint.spec.ts +12 -16
- package/src/endpoint-generators/create-patch-endpoint.spec.ts +4 -4
- package/src/endpoint-generators/create-post-endpoint.spec.ts +4 -4
- package/src/rest-service.integration.spec.ts +36 -29
- package/src/rest.integration.test.ts +10 -10
- package/src/static-server-manager.spec.ts +32 -39
- package/src/validate.integration.spec.ts +31 -36
- package/types/actions/error-action.d.ts +0 -2
- package/types/actions/error-action.d.ts.map +1 -1
- 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
|
|
30
|
-
expect(
|
|
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
|
|
50
|
+
const response = await fetch(`http://127.0.0.1:1114/api/mock?${serializeToQueryString({ select: ['id'] })}`, {
|
|
51
51
|
method: 'GET',
|
|
52
52
|
})
|
|
53
|
-
expect(
|
|
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
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
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
|
|
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.
|
|
34
|
-
|
|
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
|
|
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.
|
|
30
|
-
|
|
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
|
|
85
|
-
|
|
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
|
|
94
|
-
|
|
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
|
|
103
|
-
|
|
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
|
|
112
|
-
expect(response.
|
|
113
|
-
|
|
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
|
|
121
|
-
expect(response.
|
|
122
|
-
|
|
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
|
|
130
|
-
expect(response.
|
|
131
|
-
|
|
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
|
|
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.
|
|
144
|
-
|
|
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
|
|
159
|
+
const response = await fetch(PathHelper.joinPaths(apiUrl, 'testPostBody'), {
|
|
152
160
|
method: 'OPTIONS',
|
|
153
|
-
retry: 0,
|
|
154
161
|
})
|
|
155
|
-
expect(response.
|
|
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
|
-
|
|
164
|
-
)
|
|
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-
|
|
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
|
|
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.
|
|
63
|
-
expect(result.
|
|
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.
|
|
78
|
-
expect(result.
|
|
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.
|
|
95
|
-
expect(result.
|
|
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.
|
|
110
|
-
expect(result.
|
|
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
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
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
|
|
60
|
+
const result = await fetch(`http://localhost:${port}/not-found.html`)
|
|
66
61
|
|
|
67
|
-
expect(result.headers
|
|
68
|
-
expect(result.headers
|
|
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
|
|
82
|
+
const result = await fetch(`http://localhost:${port}`)
|
|
88
83
|
|
|
89
|
-
expect(result.headers
|
|
90
|
-
expect(result.headers
|
|
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
|
|
103
|
+
const result = await fetch(`http://localhost:${port}/README.md`)
|
|
109
104
|
|
|
110
|
-
expect(result.headers
|
|
111
|
-
expect(result.headers
|
|
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
|
|
121
|
+
const result = await fetch(`http://localhost:${port}/packages/utils/README.md`)
|
|
127
122
|
|
|
128
|
-
expect(result.headers
|
|
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
|
-
|
|
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
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
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
|
|
186
|
+
const result = await fetch(`http://localhost:${port}/bundle/not-found.html`)
|
|
194
187
|
|
|
195
|
-
expect(result.headers
|
|
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
|
|
203
|
+
const result = await fetch(`http://localhost:${port}/README.md`)
|
|
211
204
|
|
|
212
|
-
expect(result.headers
|
|
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
|
|
220
|
+
const result = await fetch(`http://localhost:${port}/packages/utils/README.md`)
|
|
228
221
|
|
|
229
|
-
expect(result.headers
|
|
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-
|
|
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
|
|
79
|
-
expect(error.message).toBe('
|
|
80
|
-
expect(error.response?.
|
|
81
|
-
const responseJson =
|
|
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
|
|
100
|
-
expect(error.message).toBe('
|
|
101
|
-
expect(error.response?.
|
|
102
|
-
const responseJson =
|
|
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
|
|
120
|
-
expect(error.message).toBe('
|
|
121
|
-
expect(error.response?.
|
|
122
|
-
const responseJson =
|
|
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
|
|
141
|
-
expect(error.message).toBe('
|
|
142
|
-
expect(error.response?.
|
|
143
|
-
const responseJson =
|
|
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.
|
|
164
|
-
|
|
165
|
-
expect(
|
|
166
|
-
expect(
|
|
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.
|
|
178
|
-
|
|
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.
|
|
194
|
-
|
|
195
|
-
expect(
|
|
196
|
-
expect(
|
|
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.
|
|
213
|
-
|
|
214
|
-
expect(
|
|
215
|
-
expect(
|
|
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
|
})
|
|
@@ -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,
|
|
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":"
|
|
1
|
+
{"version":3,"file":"validate.integration.spec.d.ts","sourceRoot":"","sources":["../src/validate.integration.spec.ts"],"names":[],"mappings":"AAKA,OAAO,WAAW,CAAA"}
|