@api-client/core 0.19.23 → 0.19.25
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/build/src/browser.d.ts +3 -0
- package/build/src/browser.d.ts.map +1 -1
- package/build/src/browser.js +2 -0
- package/build/src/browser.js.map +1 -1
- package/build/src/index.d.ts +5 -0
- package/build/src/index.d.ts.map +1 -1
- package/build/src/index.js +4 -0
- package/build/src/index.js.map +1 -1
- package/build/src/mocking/ModelingMock.d.ts +2 -0
- package/build/src/mocking/ModelingMock.d.ts.map +1 -1
- package/build/src/mocking/ModelingMock.js +2 -0
- package/build/src/mocking/ModelingMock.js.map +1 -1
- package/build/src/mocking/lib/Deployment.d.ts +16 -0
- package/build/src/mocking/lib/Deployment.d.ts.map +1 -0
- package/build/src/mocking/lib/Deployment.js +76 -0
- package/build/src/mocking/lib/Deployment.js.map +1 -0
- package/build/src/modeling/Bindings.d.ts +4 -0
- package/build/src/modeling/Bindings.d.ts.map +1 -1
- package/build/src/modeling/Bindings.js.map +1 -1
- package/build/src/modeling/DataFormat.d.ts +1 -1
- package/build/src/modeling/DataFormat.d.ts.map +1 -1
- package/build/src/modeling/DataFormat.js +2 -0
- package/build/src/modeling/DataFormat.js.map +1 -1
- package/build/src/modeling/DomainAssociation.d.ts +7 -0
- package/build/src/modeling/DomainAssociation.d.ts.map +1 -1
- package/build/src/modeling/DomainAssociation.js +10 -0
- package/build/src/modeling/DomainAssociation.js.map +1 -1
- package/build/src/modeling/DomainEntity.d.ts +9 -1
- package/build/src/modeling/DomainEntity.d.ts.map +1 -1
- package/build/src/modeling/DomainEntity.js +26 -1
- package/build/src/modeling/DomainEntity.js.map +1 -1
- package/build/src/modeling/ExposedEntity.d.ts +12 -1
- package/build/src/modeling/ExposedEntity.d.ts.map +1 -1
- package/build/src/modeling/ExposedEntity.js +24 -1
- package/build/src/modeling/ExposedEntity.js.map +1 -1
- package/build/src/modeling/RuntimeApiModel.d.ts +52 -0
- package/build/src/modeling/RuntimeApiModel.d.ts.map +1 -0
- package/build/src/modeling/RuntimeApiModel.js +85 -0
- package/build/src/modeling/RuntimeApiModel.js.map +1 -0
- package/build/src/modeling/actions/index.d.ts +10 -0
- package/build/src/modeling/actions/index.d.ts.map +1 -1
- package/build/src/modeling/actions/index.js +30 -0
- package/build/src/modeling/actions/index.js.map +1 -1
- package/build/src/modeling/index.d.ts.map +1 -1
- package/build/src/modeling/index.js +1 -0
- package/build/src/modeling/index.js.map +1 -1
- package/build/src/modeling/types.d.ts +25 -1
- package/build/src/modeling/types.d.ts.map +1 -1
- package/build/src/modeling/types.js.map +1 -1
- package/build/src/models/kinds.d.ts +1 -0
- package/build/src/models/kinds.d.ts.map +1 -1
- package/build/src/models/kinds.js +1 -0
- package/build/src/models/kinds.js.map +1 -1
- package/build/src/models/store/CustomDomain.d.ts +50 -0
- package/build/src/models/store/CustomDomain.d.ts.map +1 -0
- package/build/src/models/store/CustomDomain.js +79 -0
- package/build/src/models/store/CustomDomain.js.map +1 -0
- package/build/src/models/store/Deployment.d.ts +118 -0
- package/build/src/models/store/Deployment.d.ts.map +1 -0
- package/build/src/models/store/Deployment.js +182 -0
- package/build/src/models/store/Deployment.js.map +1 -0
- package/build/src/models/store/DeploymentCustomDomain.d.ts +52 -0
- package/build/src/models/store/DeploymentCustomDomain.d.ts.map +1 -0
- package/build/src/models/store/DeploymentCustomDomain.js +84 -0
- package/build/src/models/store/DeploymentCustomDomain.js.map +1 -0
- package/build/src/sdk/DataCatalogSdk.d.ts.map +1 -1
- package/build/src/sdk/DataCatalogSdk.js +22 -179
- package/build/src/sdk/DataCatalogSdk.js.map +1 -1
- package/build/src/sdk/DeploymentsSdk.d.ts +48 -0
- package/build/src/sdk/DeploymentsSdk.d.ts.map +1 -0
- package/build/src/sdk/DeploymentsSdk.js +94 -0
- package/build/src/sdk/DeploymentsSdk.js.map +1 -0
- package/build/src/sdk/RouteBuilder.d.ts +2 -0
- package/build/src/sdk/RouteBuilder.d.ts.map +1 -1
- package/build/src/sdk/RouteBuilder.js +6 -0
- package/build/src/sdk/RouteBuilder.js.map +1 -1
- package/build/src/sdk/Sdk.d.ts +2 -0
- package/build/src/sdk/Sdk.d.ts.map +1 -1
- package/build/src/sdk/Sdk.js +2 -0
- package/build/src/sdk/Sdk.js.map +1 -1
- package/build/src/sdk/SdkBase.d.ts +19 -1
- package/build/src/sdk/SdkBase.d.ts.map +1 -1
- package/build/src/sdk/SdkBase.js +31 -1
- package/build/src/sdk/SdkBase.js.map +1 -1
- package/build/src/sdk/SdkMock.d.ts +9 -0
- package/build/src/sdk/SdkMock.d.ts.map +1 -1
- package/build/src/sdk/SdkMock.js +73 -0
- package/build/src/sdk/SdkMock.js.map +1 -1
- package/build/tsconfig.tsbuildinfo +1 -1
- package/package.json +2 -1
- package/src/matchit.d.ts +19 -0
- package/src/mocking/ModelingMock.ts +2 -0
- package/src/mocking/lib/Deployment.ts +88 -0
- package/src/modeling/Bindings.ts +4 -0
- package/src/modeling/DataFormat.ts +4 -0
- package/src/modeling/DomainAssociation.ts +11 -0
- package/src/modeling/DomainEntity.ts +30 -1
- package/src/modeling/ExposedEntity.ts +26 -1
- package/src/modeling/RuntimeApiModel.ts +137 -0
- package/src/modeling/types.ts +26 -1
- package/src/models/kinds.ts +1 -0
- package/src/models/store/CustomDomain.ts +119 -0
- package/src/models/store/Deployment.ts +250 -0
- package/src/models/store/DeploymentCustomDomain.ts +120 -0
- package/src/sdk/DataCatalogSdk.ts +22 -176
- package/src/sdk/DeploymentsSdk.ts +123 -0
- package/src/sdk/RouteBuilder.ts +8 -0
- package/src/sdk/Sdk.ts +3 -0
- package/src/sdk/SdkBase.ts +35 -3
- package/src/sdk/SdkMock.ts +103 -0
- package/tests/unit/modeling/RuntimeApiModel.spec.ts +122 -0
- package/tests/unit/modeling/actions/index.spec.ts +113 -0
- package/tests/unit/modeling/domain_asociation.spec.ts +28 -0
- package/tests/unit/modeling/domain_entity_parents.spec.ts +49 -0
- package/tests/unit/modeling/exposed_entity_actions.spec.ts +47 -0
- package/tests/unit/models/store/CustomDomain.spec.ts +111 -0
- package/tests/unit/models/store/Deployment.spec.ts +198 -0
- package/tests/unit/models/store/DeploymentCustomDomain.spec.ts +122 -0
|
@@ -198,4 +198,51 @@ test.group('ExposedEntity::actions', (group) => {
|
|
|
198
198
|
assert.equal(restoredAction.kind, 'search', 'Action kind should be search')
|
|
199
199
|
assert.instanceOf(restoredAction, SearchAction, 'Action should be an instance of SearchAction')
|
|
200
200
|
}).tags(['@modeling', '@action', '@restoring'])
|
|
201
|
+
|
|
202
|
+
test('addActionFromKind adds a new action', ({ assert }) => {
|
|
203
|
+
const model = new ApiModel(
|
|
204
|
+
{
|
|
205
|
+
exposes: [
|
|
206
|
+
{
|
|
207
|
+
kind: ExposedEntityKind,
|
|
208
|
+
key: nanoid(),
|
|
209
|
+
entity: { key: entity.key },
|
|
210
|
+
isRoot: true,
|
|
211
|
+
hasCollection: false,
|
|
212
|
+
resourcePath: '',
|
|
213
|
+
actions: [],
|
|
214
|
+
},
|
|
215
|
+
],
|
|
216
|
+
},
|
|
217
|
+
domain
|
|
218
|
+
)
|
|
219
|
+
const expose = Array.from(model.exposes.values())[0]!
|
|
220
|
+
const action = expose.addActionFromKind('list')
|
|
221
|
+
assert.instanceOf(action, ListAction)
|
|
222
|
+
assert.equal(action.kind, 'list')
|
|
223
|
+
assert.lengthOf(expose.actions, 1)
|
|
224
|
+
assert.strictEqual(expose.actions[0], action)
|
|
225
|
+
}).tags(['@modeling', '@action'])
|
|
226
|
+
|
|
227
|
+
test('addActionFromKind throws if action already exists', ({ assert }) => {
|
|
228
|
+
const model = new ApiModel(
|
|
229
|
+
{
|
|
230
|
+
exposes: [
|
|
231
|
+
{
|
|
232
|
+
kind: ExposedEntityKind,
|
|
233
|
+
key: nanoid(),
|
|
234
|
+
entity: { key: entity.key },
|
|
235
|
+
isRoot: true,
|
|
236
|
+
hasCollection: false,
|
|
237
|
+
resourcePath: '',
|
|
238
|
+
actions: [],
|
|
239
|
+
},
|
|
240
|
+
],
|
|
241
|
+
},
|
|
242
|
+
domain
|
|
243
|
+
)
|
|
244
|
+
const expose = Array.from(model.exposes.values())[0]!
|
|
245
|
+
expose.addActionFromKind('list')
|
|
246
|
+
assert.throws(() => expose.addActionFromKind('list'), 'Action of kind "list" already exists for this exposure')
|
|
247
|
+
}).tags(['@modeling', '@action'])
|
|
201
248
|
})
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import { test } from '@japa/runner'
|
|
2
|
+
import { CustomDomainModel } from '../../../../src/models/store/CustomDomain.js'
|
|
3
|
+
import type { CustomDomainSchema } from '../../../../src/models/store/CustomDomain.js'
|
|
4
|
+
|
|
5
|
+
test.group('CustomDomain model', () => {
|
|
6
|
+
test('createSchema() returns default values', ({ assert }) => {
|
|
7
|
+
const result = CustomDomainModel.createSchema()
|
|
8
|
+
assert.isString(result.id)
|
|
9
|
+
assert.equal(result.orgId, '')
|
|
10
|
+
assert.equal(result.domain, '')
|
|
11
|
+
assert.equal(result.dnsTarget, '')
|
|
12
|
+
assert.isFalse(result.dnsVerified)
|
|
13
|
+
assert.isUndefined(result.lastVerifiedAt)
|
|
14
|
+
assert.isNumber(result.createdAt)
|
|
15
|
+
assert.isNumber(result.updatedAt)
|
|
16
|
+
})
|
|
17
|
+
|
|
18
|
+
test('createSchema(init) assigns values', ({ assert }) => {
|
|
19
|
+
const init: Partial<CustomDomainSchema> = {
|
|
20
|
+
id: 'test-id',
|
|
21
|
+
orgId: 'org-1',
|
|
22
|
+
domain: 'api.example.com',
|
|
23
|
+
dnsTarget: 'target.example.com',
|
|
24
|
+
dnsVerified: true,
|
|
25
|
+
lastVerifiedAt: 11111,
|
|
26
|
+
createdAt: 12345,
|
|
27
|
+
updatedAt: 67890,
|
|
28
|
+
}
|
|
29
|
+
const result = CustomDomainModel.createSchema(init)
|
|
30
|
+
assert.equal(result.id, 'test-id')
|
|
31
|
+
assert.equal(result.orgId, 'org-1')
|
|
32
|
+
assert.equal(result.domain, 'api.example.com')
|
|
33
|
+
assert.equal(result.dnsTarget, 'target.example.com')
|
|
34
|
+
assert.isTrue(result.dnsVerified)
|
|
35
|
+
assert.equal(result.lastVerifiedAt, 11111)
|
|
36
|
+
assert.equal(result.createdAt, 12345)
|
|
37
|
+
assert.equal(result.updatedAt, 67890)
|
|
38
|
+
})
|
|
39
|
+
|
|
40
|
+
test('constructor() initializes with default values', ({ assert }) => {
|
|
41
|
+
const model = new CustomDomainModel()
|
|
42
|
+
assert.isString(model.id)
|
|
43
|
+
assert.equal(model.orgId, '')
|
|
44
|
+
assert.equal(model.domain, '')
|
|
45
|
+
assert.equal(model.dnsTarget, '')
|
|
46
|
+
assert.isFalse(model.dnsVerified)
|
|
47
|
+
assert.isUndefined(model.lastVerifiedAt)
|
|
48
|
+
assert.isNumber(model.createdAt)
|
|
49
|
+
assert.isNumber(model.updatedAt)
|
|
50
|
+
})
|
|
51
|
+
|
|
52
|
+
test('constructor(init) assigns values', ({ assert }) => {
|
|
53
|
+
const init: Partial<CustomDomainSchema> = {
|
|
54
|
+
orgId: 'org-1',
|
|
55
|
+
domain: 'api.example.com',
|
|
56
|
+
dnsVerified: true,
|
|
57
|
+
}
|
|
58
|
+
const model = new CustomDomainModel(init)
|
|
59
|
+
assert.equal(model.orgId, 'org-1')
|
|
60
|
+
assert.equal(model.domain, 'api.example.com')
|
|
61
|
+
assert.isTrue(model.dnsVerified)
|
|
62
|
+
})
|
|
63
|
+
|
|
64
|
+
test('toJSON() returns the schema representation', ({ assert }) => {
|
|
65
|
+
const init: Partial<CustomDomainSchema> = {
|
|
66
|
+
id: 'test-id',
|
|
67
|
+
orgId: 'org-1',
|
|
68
|
+
domain: 'api.example.com',
|
|
69
|
+
dnsTarget: 'target.example.com',
|
|
70
|
+
dnsVerified: true,
|
|
71
|
+
lastVerifiedAt: 11111,
|
|
72
|
+
createdAt: 12345,
|
|
73
|
+
updatedAt: 67890,
|
|
74
|
+
}
|
|
75
|
+
const model = new CustomDomainModel(init)
|
|
76
|
+
const result = model.toJSON()
|
|
77
|
+
assert.deepEqual(result, {
|
|
78
|
+
id: 'test-id',
|
|
79
|
+
orgId: 'org-1',
|
|
80
|
+
domain: 'api.example.com',
|
|
81
|
+
dnsTarget: 'target.example.com',
|
|
82
|
+
dnsVerified: true,
|
|
83
|
+
lastVerifiedAt: 11111,
|
|
84
|
+
createdAt: 12345,
|
|
85
|
+
updatedAt: 67890,
|
|
86
|
+
})
|
|
87
|
+
})
|
|
88
|
+
|
|
89
|
+
test('validate() returns errors for empty fields', ({ assert }) => {
|
|
90
|
+
const model = new CustomDomainModel({
|
|
91
|
+
domain: '',
|
|
92
|
+
orgId: '',
|
|
93
|
+
dnsTarget: '',
|
|
94
|
+
})
|
|
95
|
+
const errors = model.validate()
|
|
96
|
+
assert.lengthOf(errors, 3)
|
|
97
|
+
assert.deepEqual(errors[0], { field: 'domain', message: 'Domain must not be empty', rule: 'notEmpty' })
|
|
98
|
+
assert.deepEqual(errors[1], { field: 'orgId', message: 'Org ID must not be empty', rule: 'notEmpty' })
|
|
99
|
+
assert.deepEqual(errors[2], { field: 'dnsTarget', message: 'DNS target must not be empty', rule: 'notEmpty' })
|
|
100
|
+
})
|
|
101
|
+
|
|
102
|
+
test('validate() returns no errors for valid model', ({ assert }) => {
|
|
103
|
+
const model = new CustomDomainModel({
|
|
104
|
+
domain: 'api.example.com',
|
|
105
|
+
orgId: 'org-1',
|
|
106
|
+
dnsTarget: 'target.example.com',
|
|
107
|
+
})
|
|
108
|
+
const errors = model.validate()
|
|
109
|
+
assert.lengthOf(errors, 0)
|
|
110
|
+
})
|
|
111
|
+
})
|
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
import { test } from '@japa/runner'
|
|
2
|
+
import { Deployment, DeploymentEnvironment, DeploymentStatus } from '../../../../src/models/store/Deployment.js'
|
|
3
|
+
import type { DeploymentSchema } from '../../../../src/models/store/Deployment.js'
|
|
4
|
+
|
|
5
|
+
test.group('Deployment model', () => {
|
|
6
|
+
test('createSchema() returns default values', ({ assert }) => {
|
|
7
|
+
const result = Deployment.createSchema()
|
|
8
|
+
assert.isString(result.key)
|
|
9
|
+
assert.equal(result.orgId, '')
|
|
10
|
+
assert.equal(result.apiId, '')
|
|
11
|
+
assert.equal(result.orgSlug, '')
|
|
12
|
+
assert.equal(result.apiSlug, '')
|
|
13
|
+
assert.equal(result.env, DeploymentEnvironment.DEV)
|
|
14
|
+
assert.isUndefined(result.version)
|
|
15
|
+
assert.equal(result.modelVersion, '0.0.0')
|
|
16
|
+
assert.equal(result.status, DeploymentStatus.Pending)
|
|
17
|
+
assert.isNumber(result.createdAt)
|
|
18
|
+
assert.isNumber(result.updatedAt)
|
|
19
|
+
})
|
|
20
|
+
|
|
21
|
+
test('createSchema(init) assigns values', ({ assert }) => {
|
|
22
|
+
const init: Partial<DeploymentSchema> = {
|
|
23
|
+
key: 'test-id',
|
|
24
|
+
orgId: 'org-1',
|
|
25
|
+
apiId: 'api-1',
|
|
26
|
+
orgSlug: 'org-slug',
|
|
27
|
+
apiSlug: 'api-slug',
|
|
28
|
+
env: DeploymentEnvironment.PROD,
|
|
29
|
+
version: 'v1',
|
|
30
|
+
modelVersion: '1.0.0',
|
|
31
|
+
status: DeploymentStatus.Active,
|
|
32
|
+
createdAt: 12345,
|
|
33
|
+
updatedAt: 67890,
|
|
34
|
+
}
|
|
35
|
+
const result = Deployment.createSchema(init)
|
|
36
|
+
assert.equal(result.key, 'test-id')
|
|
37
|
+
assert.equal(result.orgId, 'org-1')
|
|
38
|
+
assert.equal(result.apiId, 'api-1')
|
|
39
|
+
assert.equal(result.orgSlug, 'org-slug')
|
|
40
|
+
assert.equal(result.apiSlug, 'api-slug')
|
|
41
|
+
assert.equal(result.env, DeploymentEnvironment.PROD)
|
|
42
|
+
assert.equal(result.version, 'v1')
|
|
43
|
+
assert.equal(result.modelVersion, '1.0.0')
|
|
44
|
+
assert.equal(result.status, DeploymentStatus.Active)
|
|
45
|
+
assert.equal(result.createdAt, 12345)
|
|
46
|
+
assert.equal(result.updatedAt, 67890)
|
|
47
|
+
})
|
|
48
|
+
|
|
49
|
+
test('constructor() initializes with default values', ({ assert }) => {
|
|
50
|
+
const deployment = new Deployment()
|
|
51
|
+
assert.isString(deployment.key)
|
|
52
|
+
assert.equal(deployment.orgId, '')
|
|
53
|
+
assert.equal(deployment.apiId, '')
|
|
54
|
+
assert.equal(deployment.orgSlug, '')
|
|
55
|
+
assert.equal(deployment.apiSlug, '')
|
|
56
|
+
assert.equal(deployment.env, DeploymentEnvironment.DEV)
|
|
57
|
+
assert.isUndefined(deployment.version)
|
|
58
|
+
assert.equal(deployment.modelVersion, '0.0.0')
|
|
59
|
+
assert.equal(deployment.status, DeploymentStatus.Pending)
|
|
60
|
+
assert.isNumber(deployment.createdAt)
|
|
61
|
+
assert.isNumber(deployment.updatedAt)
|
|
62
|
+
})
|
|
63
|
+
|
|
64
|
+
test('constructor(init) assigns values', ({ assert }) => {
|
|
65
|
+
const init: Partial<DeploymentSchema> = {
|
|
66
|
+
orgId: 'org-1',
|
|
67
|
+
apiId: 'api-1',
|
|
68
|
+
}
|
|
69
|
+
const deployment = new Deployment(init)
|
|
70
|
+
assert.equal(deployment.orgId, 'org-1')
|
|
71
|
+
assert.equal(deployment.apiId, 'api-1')
|
|
72
|
+
})
|
|
73
|
+
|
|
74
|
+
test('toJSON() returns the schema representation', ({ assert }) => {
|
|
75
|
+
const init: Partial<DeploymentSchema> = {
|
|
76
|
+
key: 'test-id',
|
|
77
|
+
orgId: 'org-1',
|
|
78
|
+
apiId: 'api-1',
|
|
79
|
+
orgSlug: 'org-slug',
|
|
80
|
+
apiSlug: 'api-slug',
|
|
81
|
+
env: DeploymentEnvironment.PROD,
|
|
82
|
+
version: 'v1',
|
|
83
|
+
modelVersion: '1.0.0',
|
|
84
|
+
status: DeploymentStatus.Active,
|
|
85
|
+
createdAt: 12345,
|
|
86
|
+
updatedAt: 67890,
|
|
87
|
+
}
|
|
88
|
+
const deployment = new Deployment(init)
|
|
89
|
+
const result = deployment.toJSON()
|
|
90
|
+
assert.deepEqual(result, {
|
|
91
|
+
kind: 'Core#Deployment',
|
|
92
|
+
key: 'test-id',
|
|
93
|
+
orgId: 'org-1',
|
|
94
|
+
apiId: 'api-1',
|
|
95
|
+
orgSlug: 'org-slug',
|
|
96
|
+
apiSlug: 'api-slug',
|
|
97
|
+
env: DeploymentEnvironment.PROD,
|
|
98
|
+
version: 'v1',
|
|
99
|
+
modelVersion: '1.0.0',
|
|
100
|
+
status: DeploymentStatus.Active,
|
|
101
|
+
createdAt: 12345,
|
|
102
|
+
updatedAt: 67890,
|
|
103
|
+
})
|
|
104
|
+
})
|
|
105
|
+
|
|
106
|
+
test('validate() returns errors for empty fields', ({ assert }) => {
|
|
107
|
+
const deployment = new Deployment({
|
|
108
|
+
orgId: '',
|
|
109
|
+
apiId: '',
|
|
110
|
+
orgSlug: '',
|
|
111
|
+
apiSlug: '',
|
|
112
|
+
env: '' as any, // Force empty env
|
|
113
|
+
})
|
|
114
|
+
deployment.version = ''
|
|
115
|
+
deployment.modelVersion = ''
|
|
116
|
+
const errors = deployment.validate()
|
|
117
|
+
// It should now return errors for orgId, apiId, orgSlug, apiSlug, env, modelVersion
|
|
118
|
+
// Note: Since env is empty, the version-prod logic won't hit the first branch, but might hit the second branch
|
|
119
|
+
// if version is present. Since version='', neither branch hits.
|
|
120
|
+
assert.lengthOf(errors, 6)
|
|
121
|
+
assert.deepEqual(errors[0], { field: 'orgId', message: 'Org ID must not be empty', rule: 'notEmpty' })
|
|
122
|
+
assert.deepEqual(errors[1], { field: 'apiId', message: 'API ID must not be empty', rule: 'notEmpty' })
|
|
123
|
+
assert.deepEqual(errors[2], { field: 'orgSlug', message: 'Org slug must not be empty', rule: 'notEmpty' })
|
|
124
|
+
assert.deepEqual(errors[3], { field: 'apiSlug', message: 'API slug must not be empty', rule: 'notEmpty' })
|
|
125
|
+
assert.deepEqual(errors[4], { field: 'env', message: 'Environment tag must not be empty', rule: 'notEmpty' })
|
|
126
|
+
assert.deepEqual(errors[5], {
|
|
127
|
+
field: 'modelVersion',
|
|
128
|
+
message: 'API model version must not be empty',
|
|
129
|
+
rule: 'notEmpty',
|
|
130
|
+
})
|
|
131
|
+
})
|
|
132
|
+
|
|
133
|
+
test('validate() returns error if version is empty for PROD environment', ({ assert }) => {
|
|
134
|
+
const deployment = new Deployment({
|
|
135
|
+
orgId: 'org-1',
|
|
136
|
+
apiId: 'api-1',
|
|
137
|
+
orgSlug: 'org-slug',
|
|
138
|
+
apiSlug: 'api-slug',
|
|
139
|
+
env: DeploymentEnvironment.PROD,
|
|
140
|
+
modelVersion: '1.0.0',
|
|
141
|
+
})
|
|
142
|
+
// Version is undefined by default, or we can explicitly set it to empty string
|
|
143
|
+
deployment.version = ''
|
|
144
|
+
const errors = deployment.validate()
|
|
145
|
+
assert.lengthOf(errors, 1)
|
|
146
|
+
assert.deepEqual(errors[0], {
|
|
147
|
+
field: 'version',
|
|
148
|
+
message: 'Version must not be empty for production environment',
|
|
149
|
+
rule: 'notEmpty',
|
|
150
|
+
})
|
|
151
|
+
})
|
|
152
|
+
|
|
153
|
+
test('validate() returns error if version is present for non-PROD environment', ({ assert }) => {
|
|
154
|
+
const deployment = new Deployment({
|
|
155
|
+
orgId: 'org-1',
|
|
156
|
+
apiId: 'api-1',
|
|
157
|
+
orgSlug: 'org-slug',
|
|
158
|
+
apiSlug: 'api-slug',
|
|
159
|
+
env: DeploymentEnvironment.DEV,
|
|
160
|
+
version: 'v1',
|
|
161
|
+
modelVersion: '1.0.0',
|
|
162
|
+
})
|
|
163
|
+
const errors = deployment.validate()
|
|
164
|
+
assert.lengthOf(errors, 1)
|
|
165
|
+
assert.deepEqual(errors[0], {
|
|
166
|
+
field: 'version',
|
|
167
|
+
message: 'Version must not be present for non-production environment',
|
|
168
|
+
rule: 'notEmpty',
|
|
169
|
+
})
|
|
170
|
+
})
|
|
171
|
+
|
|
172
|
+
test('validate() returns no errors for valid model', ({ assert }) => {
|
|
173
|
+
const deployment = new Deployment({
|
|
174
|
+
orgId: 'org-1',
|
|
175
|
+
apiId: 'api-1',
|
|
176
|
+
version: 'v1',
|
|
177
|
+
modelVersion: '1.0.0',
|
|
178
|
+
orgSlug: 'org-slug',
|
|
179
|
+
apiSlug: 'api-slug',
|
|
180
|
+
env: DeploymentEnvironment.PROD,
|
|
181
|
+
})
|
|
182
|
+
const errors = deployment.validate()
|
|
183
|
+
assert.lengthOf(errors, 0)
|
|
184
|
+
})
|
|
185
|
+
|
|
186
|
+
test('validate() returns no errors for valid non-PROD model', ({ assert }) => {
|
|
187
|
+
const deployment = new Deployment({
|
|
188
|
+
orgId: 'org-1',
|
|
189
|
+
apiId: 'api-1',
|
|
190
|
+
modelVersion: '1.0.0',
|
|
191
|
+
orgSlug: 'org-slug',
|
|
192
|
+
apiSlug: 'api-slug',
|
|
193
|
+
env: DeploymentEnvironment.DEV,
|
|
194
|
+
})
|
|
195
|
+
const errors = deployment.validate()
|
|
196
|
+
assert.lengthOf(errors, 0)
|
|
197
|
+
})
|
|
198
|
+
})
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
import { test } from '@japa/runner'
|
|
2
|
+
import { DeploymentCustomDomainModel, SslStatus } from '../../../../src/models/store/DeploymentCustomDomain.js'
|
|
3
|
+
import type { DeploymentCustomDomainSchema } from '../../../../src/models/store/DeploymentCustomDomain.js'
|
|
4
|
+
|
|
5
|
+
test.group('DeploymentCustomDomain model', () => {
|
|
6
|
+
test('createSchema() returns default values', ({ assert }) => {
|
|
7
|
+
const result = DeploymentCustomDomainModel.createSchema()
|
|
8
|
+
assert.isString(result.id)
|
|
9
|
+
assert.equal(result.deploymentId, '')
|
|
10
|
+
assert.equal(result.customDomainId, '')
|
|
11
|
+
assert.equal(result.basePath, '/')
|
|
12
|
+
assert.equal(result.sslStatus, SslStatus.PendingDns)
|
|
13
|
+
assert.isNumber(result.createdAt)
|
|
14
|
+
assert.isNumber(result.updatedAt)
|
|
15
|
+
})
|
|
16
|
+
|
|
17
|
+
test('createSchema(init) assigns values', ({ assert }) => {
|
|
18
|
+
const init: Partial<DeploymentCustomDomainSchema> = {
|
|
19
|
+
id: 'test-id',
|
|
20
|
+
deploymentId: 'dep-1',
|
|
21
|
+
customDomainId: 'dom-1',
|
|
22
|
+
basePath: '/api',
|
|
23
|
+
sslStatus: SslStatus.Active,
|
|
24
|
+
createdAt: 12345,
|
|
25
|
+
updatedAt: 67890,
|
|
26
|
+
}
|
|
27
|
+
const result = DeploymentCustomDomainModel.createSchema(init)
|
|
28
|
+
assert.equal(result.id, 'test-id')
|
|
29
|
+
assert.equal(result.deploymentId, 'dep-1')
|
|
30
|
+
assert.equal(result.customDomainId, 'dom-1')
|
|
31
|
+
assert.equal(result.basePath, '/api')
|
|
32
|
+
assert.equal(result.sslStatus, SslStatus.Active)
|
|
33
|
+
assert.equal(result.createdAt, 12345)
|
|
34
|
+
assert.equal(result.updatedAt, 67890)
|
|
35
|
+
})
|
|
36
|
+
|
|
37
|
+
test('constructor() initializes with default values', ({ assert }) => {
|
|
38
|
+
const model = new DeploymentCustomDomainModel()
|
|
39
|
+
assert.isString(model.id)
|
|
40
|
+
assert.equal(model.deploymentId, '')
|
|
41
|
+
assert.equal(model.customDomainId, '')
|
|
42
|
+
assert.equal(model.basePath, '/')
|
|
43
|
+
assert.equal(model.sslStatus, SslStatus.PendingDns)
|
|
44
|
+
assert.isNumber(model.createdAt)
|
|
45
|
+
assert.isNumber(model.updatedAt)
|
|
46
|
+
})
|
|
47
|
+
|
|
48
|
+
test('constructor(init) assigns values', ({ assert }) => {
|
|
49
|
+
const init: Partial<DeploymentCustomDomainSchema> = {
|
|
50
|
+
deploymentId: 'dep-1',
|
|
51
|
+
customDomainId: 'dom-1',
|
|
52
|
+
basePath: '/api',
|
|
53
|
+
}
|
|
54
|
+
const model = new DeploymentCustomDomainModel(init)
|
|
55
|
+
assert.equal(model.deploymentId, 'dep-1')
|
|
56
|
+
assert.equal(model.customDomainId, 'dom-1')
|
|
57
|
+
assert.equal(model.basePath, '/api')
|
|
58
|
+
})
|
|
59
|
+
|
|
60
|
+
test('toJSON() returns the schema representation', ({ assert }) => {
|
|
61
|
+
const init: Partial<DeploymentCustomDomainSchema> = {
|
|
62
|
+
id: 'test-id',
|
|
63
|
+
deploymentId: 'dep-1',
|
|
64
|
+
customDomainId: 'dom-1',
|
|
65
|
+
basePath: '/api',
|
|
66
|
+
sslStatus: SslStatus.Active,
|
|
67
|
+
createdAt: 12345,
|
|
68
|
+
updatedAt: 67890,
|
|
69
|
+
}
|
|
70
|
+
const model = new DeploymentCustomDomainModel(init)
|
|
71
|
+
const result = model.toJSON()
|
|
72
|
+
assert.deepEqual(result, {
|
|
73
|
+
id: 'test-id',
|
|
74
|
+
deploymentId: 'dep-1',
|
|
75
|
+
customDomainId: 'dom-1',
|
|
76
|
+
basePath: '/api',
|
|
77
|
+
sslStatus: SslStatus.Active,
|
|
78
|
+
createdAt: 12345,
|
|
79
|
+
updatedAt: 67890,
|
|
80
|
+
})
|
|
81
|
+
})
|
|
82
|
+
|
|
83
|
+
test('validate() returns errors for empty and invalid fields', ({ assert }) => {
|
|
84
|
+
const model = new DeploymentCustomDomainModel({
|
|
85
|
+
basePath: '',
|
|
86
|
+
deploymentId: '',
|
|
87
|
+
customDomainId: '',
|
|
88
|
+
})
|
|
89
|
+
let errors = model.validate()
|
|
90
|
+
assert.lengthOf(errors, 3)
|
|
91
|
+
assert.deepEqual(errors[0], { field: 'basePath', message: 'Base path must not be empty', rule: 'notEmpty' })
|
|
92
|
+
assert.deepEqual(errors[1], { field: 'deploymentId', message: 'Deployment ID must not be empty', rule: 'notEmpty' })
|
|
93
|
+
assert.deepEqual(errors[2], {
|
|
94
|
+
field: 'customDomainId',
|
|
95
|
+
message: 'Custom domain ID must not be empty',
|
|
96
|
+
rule: 'notEmpty',
|
|
97
|
+
})
|
|
98
|
+
|
|
99
|
+
const modelInvalidPath = new DeploymentCustomDomainModel({
|
|
100
|
+
basePath: 'api/path',
|
|
101
|
+
deploymentId: 'dep-1',
|
|
102
|
+
customDomainId: 'dom-1',
|
|
103
|
+
})
|
|
104
|
+
errors = modelInvalidPath.validate()
|
|
105
|
+
assert.lengthOf(errors, 1)
|
|
106
|
+
assert.deepEqual(errors[0], {
|
|
107
|
+
field: 'basePath',
|
|
108
|
+
message: 'Base path must start with a slash',
|
|
109
|
+
rule: 'startsWithSlash',
|
|
110
|
+
})
|
|
111
|
+
})
|
|
112
|
+
|
|
113
|
+
test('validate() returns no errors for valid model', ({ assert }) => {
|
|
114
|
+
const model = new DeploymentCustomDomainModel({
|
|
115
|
+
deploymentId: 'dep-1',
|
|
116
|
+
customDomainId: 'dom-1',
|
|
117
|
+
basePath: '/api',
|
|
118
|
+
})
|
|
119
|
+
const errors = model.validate()
|
|
120
|
+
assert.lengthOf(errors, 0)
|
|
121
|
+
})
|
|
122
|
+
})
|