1
- import { expect } from "vitest" ;
2
- import { contentTypeHandlers } from "../../src/handlers/content-type-handlers.js" ;
3
- import { server } from "../msw-setup.js" ;
1
+ import { expect } from "vitest"
2
+ import { contentTypeHandlers } from "../../src/handlers/content-type-handlers.js"
3
+ import { server } from "../msw-setup.js"
4
+ import { toCamelCase } from "../../src/utils/to-camel-case.js"
4
5
5
6
describe ( "Content Type Handlers Integration Tests" , ( ) => {
6
7
// Start MSW Server before tests
7
- beforeAll ( ( ) => server . listen ( ) ) ;
8
- afterEach ( ( ) => server . resetHandlers ( ) ) ;
9
- afterAll ( ( ) => server . close ( ) ) ;
8
+ beforeAll ( ( ) => server . listen ( ) )
9
+ afterEach ( ( ) => server . resetHandlers ( ) )
10
+ afterAll ( ( ) => server . close ( ) )
10
11
11
- const testSpaceId = "test-space-id" ;
12
- const testContentTypeId = "test-content-type-id" ;
12
+ const testSpaceId = "test-space-id"
13
+ const testContentTypeId = "test-content-type-id"
13
14
14
15
describe ( "listContentTypes" , ( ) => {
15
16
it ( "should list all content types" , async ( ) => {
16
17
const result = await contentTypeHandlers . listContentTypes ( {
17
18
spaceId : testSpaceId ,
18
- } ) ;
19
-
20
- expect ( result ) . to . have . property ( "content" ) . that . is . an ( "array" ) ;
21
- expect ( result . content ) . to . have . lengthOf ( 1 ) ;
22
-
23
- const contentTypes = JSON . parse ( result . content [ 0 ] . text ) ;
24
- expect ( contentTypes . items ) . to . be . an ( "array" ) ;
25
- expect ( contentTypes . items [ 0 ] ) . to . have . nested . property (
26
- "sys.id" ,
27
- "test-content-type-id" ,
28
- ) ;
29
- expect ( contentTypes . items [ 0 ] ) . to . have . property (
30
- "name" ,
31
- "Test Content Type" ,
32
- ) ;
33
- } ) ;
34
- } ) ;
19
+ } )
20
+
21
+ expect ( result ) . to . have . property ( "content" ) . that . is . an ( "array" )
22
+ expect ( result . content ) . to . have . lengthOf ( 1 )
23
+
24
+ const contentTypes = JSON . parse ( result . content [ 0 ] . text )
25
+ expect ( contentTypes . items ) . to . be . an ( "array" )
26
+ expect ( contentTypes . items [ 0 ] ) . to . have . nested . property ( "sys.id" , "test-content-type-id" )
27
+ expect ( contentTypes . items [ 0 ] ) . to . have . property ( "name" , "Test Content Type" )
28
+ } )
29
+ } )
35
30
36
31
describe ( "getContentType" , ( ) => {
37
32
it ( "should get details of a specific content type" , async ( ) => {
38
33
const result = await contentTypeHandlers . getContentType ( {
39
34
spaceId : testSpaceId ,
40
35
contentTypeId : testContentTypeId ,
41
- } ) ;
36
+ } )
42
37
43
- expect ( result ) . to . have . property ( "content" ) ;
44
- const contentType = JSON . parse ( result . content [ 0 ] . text ) ;
45
- expect ( contentType ) . to . have . nested . property ( "sys.id" , testContentTypeId ) ;
46
- expect ( contentType ) . to . have . property ( "name" , "Test Content Type" ) ;
47
- expect ( contentType . fields ) . to . be . an ( "array" ) ;
48
- } ) ;
38
+ expect ( result ) . to . have . property ( "content" )
39
+ const contentType = JSON . parse ( result . content [ 0 ] . text )
40
+ expect ( contentType ) . to . have . nested . property ( "sys.id" , toCamelCase ( testContentTypeId ) )
41
+ expect ( contentType ) . to . have . property ( "name" , "Test Content Type" )
42
+ expect ( contentType . fields ) . to . be . an ( "array" )
43
+ } )
49
44
50
45
it ( "should throw error for invalid content type ID" , async ( ) => {
51
46
try {
52
47
await contentTypeHandlers . getContentType ( {
53
48
spaceId : testSpaceId ,
54
49
contentTypeId : "invalid-id" ,
55
- } ) ;
56
- expect . fail ( "Should have thrown an error" ) ;
50
+ } )
51
+ expect . fail ( "Should have thrown an error" )
57
52
} catch ( error ) {
58
- expect ( error ) . to . exist ;
53
+ expect ( error ) . to . exist
59
54
}
60
- } ) ;
61
- } ) ;
55
+ } )
56
+ } )
62
57
63
58
describe ( "createContentType" , ( ) => {
64
59
it ( "should create a new content type" , async ( ) => {
@@ -73,21 +68,17 @@ describe("Content Type Handlers Integration Tests", () => {
73
68
required : true ,
74
69
} ,
75
70
] ,
76
- } ;
77
-
78
- const result =
79
- await contentTypeHandlers . createContentType ( contentTypeData ) ;
80
-
81
- expect ( result ) . to . have . property ( "content" ) ;
82
- const contentType = JSON . parse ( result . content [ 0 ] . text ) ;
83
- expect ( contentType ) . to . have . nested . property (
84
- "sys.id" ,
85
- "new-content-type-id" ,
86
- ) ;
87
- expect ( contentType ) . to . have . property ( "name" , "New Content Type" ) ;
88
- expect ( contentType . fields ) . to . be . an ( "array" ) ;
89
- } ) ;
90
- } ) ;
71
+ }
72
+
73
+ const result = await contentTypeHandlers . createContentType ( contentTypeData )
74
+
75
+ expect ( result ) . to . have . property ( "content" )
76
+ const contentType = JSON . parse ( result . content [ 0 ] . text )
77
+ expect ( contentType ) . to . have . nested . property ( "sys.id" , "newContentType" )
78
+ expect ( contentType ) . to . have . property ( "name" , "New Content Type" )
79
+ expect ( contentType . fields ) . to . be . an ( "array" )
80
+ } )
81
+ } )
91
82
92
83
describe ( "updateContentType" , ( ) => {
93
84
it ( "should update an existing content type" , async ( ) => {
@@ -103,62 +94,62 @@ describe("Content Type Handlers Integration Tests", () => {
103
94
required : true ,
104
95
} ,
105
96
] ,
106
- } ;
97
+ }
107
98
108
- const result = await contentTypeHandlers . updateContentType ( updateData ) ;
99
+ const result = await contentTypeHandlers . updateContentType ( updateData )
109
100
110
- expect ( result ) . to . have . property ( "content" ) ;
111
- const contentType = JSON . parse ( result . content [ 0 ] . text ) ;
112
- expect ( contentType ) . to . have . nested . property ( "sys.id" , testContentTypeId ) ;
113
- expect ( contentType ) . to . have . property ( "name" , "Updated Content Type" ) ;
114
- } ) ;
115
- } ) ;
101
+ expect ( result ) . to . have . property ( "content" )
102
+ const contentType = JSON . parse ( result . content [ 0 ] . text )
103
+ expect ( contentType ) . to . have . nested . property ( "sys.id" , testContentTypeId )
104
+ expect ( contentType ) . to . have . property ( "name" , "Updated Content Type" )
105
+ } )
106
+ } )
116
107
117
108
describe ( "deleteContentType" , ( ) => {
118
109
it ( "should delete a content type" , async ( ) => {
119
110
const result = await contentTypeHandlers . deleteContentType ( {
120
111
spaceId : testSpaceId ,
121
112
contentTypeId : testContentTypeId ,
122
- } ) ;
113
+ } )
123
114
124
- expect ( result ) . to . have . property ( "content" ) ;
125
- expect ( result . content [ 0 ] . text ) . to . include ( "deleted successfully" ) ;
126
- } ) ;
115
+ expect ( result ) . to . have . property ( "content" )
116
+ expect ( result . content [ 0 ] . text ) . to . include ( "deleted successfully" )
117
+ } )
127
118
128
119
it ( "should throw error when deleting non-existent content type" , async ( ) => {
129
120
try {
130
121
await contentTypeHandlers . deleteContentType ( {
131
122
spaceId : testSpaceId ,
132
123
contentTypeId : "non-existent-id" ,
133
- } ) ;
134
- expect . fail ( "Should have thrown an error" ) ;
124
+ } )
125
+ expect . fail ( "Should have thrown an error" )
135
126
} catch ( error ) {
136
- expect ( error ) . to . exist ;
127
+ expect ( error ) . to . exist
137
128
}
138
- } ) ;
139
- } ) ;
129
+ } )
130
+ } )
140
131
141
132
describe ( "publishContentType" , ( ) => {
142
133
it ( "should publish a content type" , async ( ) => {
143
134
const result = await contentTypeHandlers . publishContentType ( {
144
135
spaceId : testSpaceId ,
145
136
contentTypeId : testContentTypeId ,
146
- } ) ;
137
+ } )
147
138
148
- expect ( result ) . to . have . property ( "content" ) ;
149
- expect ( result . content [ 0 ] . text ) . to . include ( "published successfully" ) ;
150
- } ) ;
139
+ expect ( result ) . to . have . property ( "content" )
140
+ expect ( result . content [ 0 ] . text ) . to . include ( "published successfully" )
141
+ } )
151
142
152
143
it ( "should throw error when publishing non-existent content type" , async ( ) => {
153
144
try {
154
145
await contentTypeHandlers . publishContentType ( {
155
146
spaceId : testSpaceId ,
156
147
contentTypeId : "non-existent-id" ,
157
- } ) ;
158
- expect . fail ( "Should have thrown an error" ) ;
148
+ } )
149
+ expect . fail ( "Should have thrown an error" )
159
150
} catch ( error ) {
160
- expect ( error ) . to . exist ;
151
+ expect ( error ) . to . exist
161
152
}
162
- } ) ;
163
- } ) ;
164
- } ) ;
153
+ } )
154
+ } )
155
+ } )
0 commit comments