@@ -13,6 +13,7 @@ import path from 'path';
13
13
import * as fs from 'fs/promises' ;
14
14
import { JsonCatalogDataAdaptor } from '../repository/json_data_adaptor' ;
15
15
import { deepCheck , foldResults } from '../repository/utils' ;
16
+ import { expectErrorResult , expectOkResult } from './custom_expects' ;
16
17
17
18
const fetchSerializedIntegrations = async ( ) : Promise < Result < SerializedIntegration [ ] , Error > > => {
18
19
const directory = path . join ( __dirname , '../__data__/repository' ) ;
@@ -31,14 +32,15 @@ const fetchSerializedIntegrations = async (): Promise<Result<SerializedIntegrati
31
32
const serializedIntegrationResults = await Promise . all (
32
33
( readers . filter ( ( x ) => x !== null ) as IntegrationReader [ ] ) . map ( ( r ) => r . serialize ( ) )
33
34
) ;
34
- return foldResults ( serializedIntegrationResults ) ;
35
+ const folded = foldResults ( serializedIntegrationResults ) ;
36
+ expectOkResult ( folded ) ;
37
+ return folded ;
35
38
} ;
36
39
37
40
describe ( 'The Local Serialized Catalog' , ( ) => {
38
41
it ( 'Should serialize without errors' , async ( ) => {
39
42
const serialized = await fetchSerializedIntegrations ( ) ;
40
- expect ( serialized . error ) . not . toBeDefined ( ) ;
41
- expect ( serialized . ok ) . toBe ( true ) ;
43
+ expectOkResult ( serialized ) ;
42
44
} ) ;
43
45
44
46
it ( 'Should pass deep validation for all serialized integrations' , async ( ) => {
@@ -49,7 +51,7 @@ describe('The Local Serialized Catalog', () => {
49
51
50
52
for ( const integ of await repository . getIntegrationList ( ) ) {
51
53
const validationResult = await deepCheck ( integ ) ;
52
- await expect ( validationResult ) . toHaveProperty ( 'ok' , true ) ;
54
+ expectOkResult ( validationResult ) ;
53
55
}
54
56
} ) ;
55
57
@@ -61,7 +63,7 @@ describe('The Local Serialized Catalog', () => {
61
63
const integration = ( await repository . getIntegration ( 'nginx' ) ) as IntegrationReader ;
62
64
const logoStatic = await integration . getStatic ( 'logo.svg' ) ;
63
65
64
- expect ( logoStatic ) . toHaveProperty ( 'ok' , true ) ;
66
+ expectOkResult ( logoStatic ) ;
65
67
expect ( ( logoStatic . value as Buffer ) . length ) . toBeGreaterThan ( 100 ) ;
66
68
} ) ;
67
69
@@ -73,7 +75,7 @@ describe('The Local Serialized Catalog', () => {
73
75
const integration = ( await repository . getIntegration ( 'nginx' ) ) as IntegrationReader ;
74
76
const logoStatic = await integration . getStatic ( 'dashboard1.png' ) ;
75
77
76
- expect ( logoStatic ) . toHaveProperty ( 'ok' , true ) ;
78
+ expectOkResult ( logoStatic ) ;
77
79
expect ( ( logoStatic . value as Buffer ) . length ) . toBeGreaterThan ( 1000 ) ;
78
80
} ) ;
79
81
@@ -95,7 +97,7 @@ describe('The Local Serialized Catalog', () => {
95
97
96
98
const reader = new IntegrationReader ( 'nginx' , new JsonCatalogDataAdaptor ( [ config ] ) ) ;
97
99
98
- await expect ( reader . getStatic ( 'dark_logo.svg' ) ) . resolves . toHaveProperty ( 'ok' , true ) ;
100
+ expectOkResult ( await reader . getStatic ( 'dark_logo.svg' ) ) ;
99
101
} ) ;
100
102
101
103
it ( 'Should correctly re-serialize' , async ( ) => {
@@ -108,6 +110,7 @@ describe('The Local Serialized Catalog', () => {
108
110
const reader = new IntegrationReader ( 'nginx' , new JsonCatalogDataAdaptor ( [ config ] ) ) ;
109
111
const reserialized = await reader . serialize ( ) ;
110
112
113
+ expectOkResult ( reserialized ) ;
111
114
expect ( reserialized . value ) . toEqual ( config ) ;
112
115
} ) ;
113
116
@@ -130,6 +133,7 @@ describe('The Local Serialized Catalog', () => {
130
133
const reader = new IntegrationReader ( 'nginx' , new JsonCatalogDataAdaptor ( [ config ] ) ) ;
131
134
const reserialized = await reader . serialize ( ) ;
132
135
136
+ expectOkResult ( reserialized ) ;
133
137
expect ( reserialized . value ) . toEqual ( config ) ;
134
138
} ) ;
135
139
} ) ;
@@ -151,7 +155,7 @@ describe('Integration validation', () => {
151
155
new JsonCatalogDataAdaptor ( transformedSerialized )
152
156
) ;
153
157
154
- await expect ( deepCheck ( integration ) ) . resolves . toHaveProperty ( 'ok' , false ) ;
158
+ expectErrorResult ( await deepCheck ( integration ) ) ;
155
159
} ) ;
156
160
157
161
it ( 'Should correctly fail an integration without assets' , async ( ) => {
@@ -170,7 +174,7 @@ describe('Integration validation', () => {
170
174
new JsonCatalogDataAdaptor ( transformedSerialized )
171
175
) ;
172
176
173
- await expect ( deepCheck ( integration ) ) . resolves . toHaveProperty ( 'ok' , false ) ;
177
+ expectErrorResult ( await deepCheck ( integration ) ) ;
174
178
} ) ;
175
179
} ) ;
176
180
@@ -197,10 +201,9 @@ describe('JSON Catalog with invalid data', () => {
197
201
new JsonCatalogDataAdaptor ( [ baseConfig ] )
198
202
) ;
199
203
200
- await expect ( reader . getStatic ( 'logo.svg' ) ) . resolves . toHaveProperty ( 'ok' , false ) ;
201
- await expect ( reader . getStatic ( 'dm_logo.svg' ) ) . resolves . toHaveProperty ( 'ok' , false ) ;
202
- await expect ( reader . getStatic ( '1.png' ) ) . resolves . toHaveProperty ( 'ok' , false ) ;
203
- await expect ( reader . getStatic ( 'dm_1.png' ) ) . resolves . toHaveProperty ( 'ok' , false ) ;
204
+ for ( const img of [ 'logo.svg' , 'dm_logo.svg' , '1.png' , 'dm_1.png' ] ) {
205
+ expectErrorResult ( await reader . getStatic ( img ) ) ;
206
+ }
204
207
} ) ;
205
208
206
209
it ( 'Should report an error on read if a schema has invalid JSON' , async ( ) => {
@@ -218,6 +221,6 @@ describe('JSON Catalog with invalid data', () => {
218
221
new JsonCatalogDataAdaptor ( [ baseConfig ] )
219
222
) ;
220
223
221
- await expect ( reader . getSchemas ( ) ) . resolves . toHaveProperty ( 'ok' , false ) ;
224
+ expectErrorResult ( await reader . getSchemas ( ) ) ;
222
225
} ) ;
223
226
} ) ;
0 commit comments