@@ -79,6 +79,25 @@ test('Can create a new tag type', async () => {
79
79
} ) ;
80
80
} ) ;
81
81
82
+ test ( 'Can create a new tag type with color' , async ( ) => {
83
+ await app . request
84
+ . post ( '/api/admin/tag-types' )
85
+ . send ( {
86
+ name : 'colored-tag' ,
87
+ description : 'A tag type with a color' ,
88
+ icon : 'icon' ,
89
+ color : '#FF5733' ,
90
+ } )
91
+ . expect ( 201 ) ;
92
+ return app . request
93
+ . get ( '/api/admin/tag-types/colored-tag' )
94
+ . expect ( 'Content-Type' , / j s o n / )
95
+ . expect ( 200 )
96
+ . expect ( ( res ) => {
97
+ expect ( res . body . tagType . color ) . toBe ( '#FF5733' ) ;
98
+ } ) ;
99
+ } ) ;
100
+
82
101
test ( 'Invalid tag types gets rejected' , async ( ) => {
83
102
await app . request
84
103
. post ( '/api/admin/tag-types' )
@@ -96,6 +115,20 @@ test('Invalid tag types gets rejected', async () => {
96
115
} ) ;
97
116
} ) ;
98
117
118
+ test ( 'Tag type with invalid color format gets rejected' , async ( ) => {
119
+ const res = await app . request
120
+ . post ( '/api/admin/tag-types' )
121
+ . send ( {
122
+ name : 'invalid-color-tag' ,
123
+ description : 'A tag with invalid color' ,
124
+ color : 'not-a-color' ,
125
+ } )
126
+ . set ( 'Content-Type' , 'application/json' )
127
+ . expect ( 400 ) ;
128
+
129
+ expect ( res . body . details [ 0 ] . message ) . toMatch ( / c o l o r / ) ;
130
+ } ) ;
131
+
99
132
test ( 'Can update a tag types description and icon' , async ( ) => {
100
133
await app . request . get ( '/api/admin/tag-types/simple' ) . expect ( 200 ) ;
101
134
await app . request
@@ -113,6 +146,32 @@ test('Can update a tag types description and icon', async () => {
113
146
expect ( res . body . tagType . icon ) . toBe ( '$' ) ;
114
147
} ) ;
115
148
} ) ;
149
+
150
+ test ( 'Can update a tag type color' , async ( ) => {
151
+ await app . request
152
+ . post ( '/api/admin/tag-types' )
153
+ . send ( {
154
+ name : 'color-update-tag' ,
155
+ description : 'A tag type to test color updates' ,
156
+ color : '#FFFFFF' ,
157
+ } )
158
+ . expect ( 201 ) ;
159
+
160
+ await app . request
161
+ . put ( '/api/admin/tag-types/color-update-tag' )
162
+ . send ( {
163
+ color : '#00FF00' ,
164
+ } )
165
+ . expect ( 200 ) ;
166
+
167
+ const res = await app . request
168
+ . get ( '/api/admin/tag-types/color-update-tag' )
169
+ . expect ( 'Content-Type' , / j s o n / )
170
+ . expect ( 200 ) ;
171
+
172
+ expect ( res . body . tagType . color ) . toBe ( '#00FF00' ) ;
173
+ } ) ;
174
+
116
175
test ( 'Numbers are coerced to strings for icons and descriptions' , async ( ) => {
117
176
await app . request . get ( '/api/admin/tag-types/simple' ) . expect ( 200 ) ;
118
177
await app . request
@@ -139,6 +198,34 @@ test('Validation of tag-types returns 200 for valid tag-types', async () => {
139
198
} ) ;
140
199
} ) ;
141
200
201
+ test ( 'Validation of tag-types with valid color is successful' , async ( ) => {
202
+ const res = await app . request
203
+ . post ( '/api/admin/tag-types/validate' )
204
+ . send ( {
205
+ name : 'color-validation' ,
206
+ description : 'A tag type with a valid color' ,
207
+ color : '#123ABC' ,
208
+ } )
209
+ . set ( 'Content-Type' , 'application/json' )
210
+ . expect ( 200 ) ;
211
+
212
+ expect ( res . body . valid ) . toBe ( true ) ;
213
+ } ) ;
214
+
215
+ test ( 'Validation of tag-types with invalid color format is unsuccessful' , async ( ) => {
216
+ const res = await app . request
217
+ . post ( '/api/admin/tag-types/validate' )
218
+ . send ( {
219
+ name : 'invalid-color-validation' ,
220
+ description : 'A tag type with an invalid color' ,
221
+ color : 'not-a-color' ,
222
+ } )
223
+ . set ( 'Content-Type' , 'application/json' )
224
+ . expect ( 400 ) ;
225
+
226
+ expect ( res . body . details [ 0 ] . message ) . toMatch ( / c o l o r / ) ;
227
+ } ) ;
228
+
142
229
test ( 'Validation of tag types allows numbers for description and icons because of coercion' , async ( ) => {
143
230
await app . request
144
231
. post ( '/api/admin/tag-types/validate' )
@@ -216,3 +303,19 @@ test('Only required argument should be name', async () => {
216
303
expect ( res . body . name ) . toBe ( name ) ;
217
304
} ) ;
218
305
} ) ;
306
+
307
+ test ( 'Creating a tag type with null color is allowed' , async ( ) => {
308
+ const name = 'null-color-tag' ;
309
+ const res = await app . request
310
+ . post ( '/api/admin/tag-types' )
311
+ . send ( {
312
+ name,
313
+ description : 'A tag with null color' ,
314
+ color : null ,
315
+ } )
316
+ . set ( 'Content-Type' , 'application/json' )
317
+ . expect ( 201 ) ;
318
+
319
+ expect ( res . body . name ) . toBe ( name ) ;
320
+ expect ( res . body . color ) . toBe ( null ) ;
321
+ } ) ;
0 commit comments