@api-client/core 0.19.23 → 0.19.24

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.
@@ -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
+ })