@furystack/rest-service 6.2.1 → 6.2.3
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/api-manager.js +2 -2
- package/dist/api-manager.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 +5 -8
- 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/api-manager.ts +2 -2
- 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 +6 -6
- 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
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { usingAsync } from '@furystack/utils'
|
|
2
2
|
import { Injector } from '@furystack/inject'
|
|
3
|
-
import got from 'got'
|
|
4
3
|
import { MockClass, setupContext } from './utils'
|
|
5
4
|
import { createGetCollectionEndpoint } from './create-get-collection-endpoint'
|
|
6
5
|
import type { GetCollectionEndpoint, GetCollectionResult } from '@furystack/rest'
|
|
@@ -39,8 +38,9 @@ describe('createGetCollectionEndpoint', () => {
|
|
|
39
38
|
const count = await getDataSetFor(i, MockClass, 'id').count(i)
|
|
40
39
|
const allEntities = await getDataSetFor(i, MockClass, 'id').find(i, {})
|
|
41
40
|
|
|
42
|
-
const response = await
|
|
43
|
-
|
|
41
|
+
const response = await fetch('http://127.0.0.1:1112/api/entities', { method: 'GET' })
|
|
42
|
+
expect(response.status).toBe(200)
|
|
43
|
+
const json: GetCollectionResult<MockClass> = await response.json()
|
|
44
44
|
expect(json.count).toBe(count)
|
|
45
45
|
expect(json.entries).toEqual(allEntities)
|
|
46
46
|
})
|
|
@@ -63,10 +63,11 @@ describe('createGetCollectionEndpoint', () => {
|
|
|
63
63
|
const findOptions: FindOptions<MockClass, Array<keyof MockClass>> = { order: { value: 'ASC' } }
|
|
64
64
|
const count = await getDataSetFor(i, MockClass, 'id').count(i, findOptions.filter)
|
|
65
65
|
const orderedEntities = await getDataSetFor(i, MockClass, 'id').find(i, findOptions)
|
|
66
|
-
const response = await
|
|
66
|
+
const response = await fetch(`http://127.0.0.1:1113/api/entities?${serializeToQueryString({ findOptions })}`, {
|
|
67
67
|
method: 'GET',
|
|
68
68
|
})
|
|
69
|
-
|
|
69
|
+
expect(response.status).toBe(200)
|
|
70
|
+
const json: GetCollectionResult<MockClass> = await response.json()
|
|
70
71
|
expect(json.count).toBe(count)
|
|
71
72
|
expect(json.entries).toEqual(orderedEntities)
|
|
72
73
|
})
|
|
@@ -95,10 +96,11 @@ describe('createGetCollectionEndpoint', () => {
|
|
|
95
96
|
|
|
96
97
|
expect(filteredEntities).not.toContainEqual({ id: 'mock2', value: '3' })
|
|
97
98
|
|
|
98
|
-
const response = await
|
|
99
|
+
const response = await fetch(`http://127.0.0.1:1113/api/entities?${serializeToQueryString({ findOptions })}`, {
|
|
99
100
|
method: 'GET',
|
|
100
101
|
})
|
|
101
|
-
|
|
102
|
+
expect(response.status).toBe(200)
|
|
103
|
+
const json: GetCollectionResult<MockClass> = await response.json()
|
|
102
104
|
expect(json.count).toBe(count)
|
|
103
105
|
expect(json.entries).toEqual(filteredEntities)
|
|
104
106
|
})
|
|
@@ -127,10 +129,13 @@ describe('createGetCollectionEndpoint', () => {
|
|
|
127
129
|
|
|
128
130
|
selectedEntities.forEach((e) => expect(e.value).toBeUndefined())
|
|
129
131
|
|
|
130
|
-
const response = await
|
|
132
|
+
const response = await fetch(`http://127.0.0.1:1113/api/entities?${serializeToQueryString({ findOptions })}`, {
|
|
131
133
|
method: 'GET',
|
|
132
134
|
})
|
|
133
|
-
|
|
135
|
+
|
|
136
|
+
expect(response.status).toBe(200)
|
|
137
|
+
|
|
138
|
+
const json: GetCollectionResult<MockClass> = await response.json()
|
|
134
139
|
expect(json.count).toBe(count)
|
|
135
140
|
expect(json.entries).toEqual(selectedEntities)
|
|
136
141
|
})
|
|
@@ -161,10 +166,11 @@ describe('createGetCollectionEndpoint', () => {
|
|
|
161
166
|
expect(topSkipEntities).not.toContainEqual({ id: 'mock1', value: '4' })
|
|
162
167
|
expect(topSkipEntities).not.toContainEqual({ id: 'mock4', value: '1' })
|
|
163
168
|
|
|
164
|
-
const response = await
|
|
169
|
+
const response = await fetch(`http://127.0.0.1:1113/api/entities?${serializeToQueryString({ findOptions })}`, {
|
|
165
170
|
method: 'GET',
|
|
166
171
|
})
|
|
167
|
-
|
|
172
|
+
expect(response.status).toBe(200)
|
|
173
|
+
const json: GetCollectionResult<MockClass> = await response.json()
|
|
168
174
|
expect(json.count).toBe(count)
|
|
169
175
|
expect(json.entries).toEqual(topSkipEntities)
|
|
170
176
|
})
|
|
@@ -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'
|
|
@@ -11,23 +10,24 @@ describe('createPostEndpoint', () => {
|
|
|
11
10
|
it('Should create the entity and report the success', async () => {
|
|
12
11
|
await usingAsync(new Injector(), async (i) => {
|
|
13
12
|
setupContext(i)
|
|
14
|
-
await useRestService<{ POST: { '
|
|
13
|
+
await useRestService<{ POST: { '/': PostEndpoint<MockClass, 'id'> } }>({
|
|
15
14
|
injector: i,
|
|
16
15
|
root: '/api',
|
|
17
16
|
port: 1117,
|
|
18
17
|
api: {
|
|
19
18
|
POST: {
|
|
20
|
-
'
|
|
19
|
+
'/': createPostEndpoint({ model: MockClass, primaryKey: 'id' }),
|
|
21
20
|
},
|
|
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', {
|
|
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
|
})
|