@@ -119,6 +119,17 @@ describe("/api/config/[key]/index", () => {
119
119
} ) ;
120
120
121
121
describe ( "App config key validation" , ( ) => {
122
+ const OLD_ENV = process . env ;
123
+
124
+ beforeEach ( ( ) => {
125
+ jest . resetModules ( ) ;
126
+ process . env = { ...OLD_ENV } ;
127
+ } ) ;
128
+
129
+ afterEach ( ( ) => {
130
+ process . env = OLD_ENV ;
131
+ } ) ;
132
+
122
133
it ( "should return error for invalid config key" , async ( ) => {
123
134
const { req, res } = createAuthenticatedMocks ( {
124
135
method : "GET" ,
@@ -131,14 +142,14 @@ describe("/api/config/[key]/index", () => {
131
142
132
143
expect ( res . _getStatusCode ( ) ) . toBe ( 400 ) ;
133
144
expect ( res . _getJSONData ( ) ) . toMatchInlineSnapshot ( `
134
- {
135
- "message": "Configuration key 'some-invalid-key' doesn't exist",
136
- "method": "GET",
137
- "name": "BadRequestError",
138
- "path": "",
139
- "statusCode": 400,
140
- }
141
- ` ) ;
145
+ {
146
+ "message": "Configuration key 'some-invalid-key' doesn't exist",
147
+ "method": "GET",
148
+ "name": "BadRequestError",
149
+ "path": "",
150
+ "statusCode": 400,
151
+ }
152
+ ` ) ;
142
153
} ) ;
143
154
144
155
it ( "should return error for no config key" , async ( ) => {
@@ -151,14 +162,14 @@ describe("/api/config/[key]/index", () => {
151
162
152
163
expect ( res . _getStatusCode ( ) ) . toBe ( 400 ) ;
153
164
expect ( res . _getJSONData ( ) ) . toMatchInlineSnapshot ( `
154
- {
155
- "message": "Configuration key 'undefined' doesn't exist",
156
- "method": "GET",
157
- "name": "BadRequestError",
158
- "path": "",
159
- "statusCode": 400,
160
- }
161
- ` ) ;
165
+ {
166
+ "message": "Configuration key 'undefined' doesn't exist",
167
+ "method": "GET",
168
+ "name": "BadRequestError",
169
+ "path": "",
170
+ "statusCode": 400,
171
+ }
172
+ ` ) ;
162
173
} ) ;
163
174
164
175
it ( "should return error for entity config keys when the entity is not passed" , async ( ) => {
@@ -173,14 +184,53 @@ describe("/api/config/[key]/index", () => {
173
184
174
185
expect ( res . _getStatusCode ( ) ) . toBe ( 400 ) ;
175
186
expect ( res . _getJSONData ( ) ) . toMatchInlineSnapshot ( `
176
- {
177
- "message": "Configuration of key 'table_views' requires entity",
178
- "method": "GET",
179
- "name": "BadRequestError",
180
- "path": "",
181
- "statusCode": 400,
182
- }
183
- ` ) ;
187
+ {
188
+ "message": "Configuration of key 'table_views' requires entity",
189
+ "method": "GET",
190
+ "name": "BadRequestError",
191
+ "path": "",
192
+ "statusCode": 400,
193
+ }
194
+ ` ) ;
195
+ } ) ;
196
+
197
+ it ( "should throw error when updating a restricted config on demo" , async ( ) => {
198
+ process . env . NEXT_PUBLIC_IS_DEMO = "true" ;
199
+
200
+ const putReq = createAuthenticatedMocks ( {
201
+ method : "PUT" ,
202
+ query : {
203
+ key : "disabled_entities" ,
204
+ } ,
205
+ body : {
206
+ data : [ "updated-1" , "updated-3" ] ,
207
+ } ,
208
+ } ) ;
209
+
210
+ await handler ( putReq . req , putReq . res ) ;
211
+
212
+ expect ( putReq . res . _getStatusCode ( ) ) . toBe ( 400 ) ;
213
+ expect ( putReq . res . _getJSONData ( ) ) . toMatchInlineSnapshot ( `
214
+ {
215
+ "message": "This action is not available on the demo site",
216
+ "method": "PUT",
217
+ "name": "BadRequestError",
218
+ "path": "",
219
+ "statusCode": 400,
220
+ }
221
+ ` ) ;
222
+
223
+ const getReq = createAuthenticatedMocks ( {
224
+ method : "GET" ,
225
+ query : {
226
+ key : "disabled_entities" ,
227
+ } ,
228
+ } ) ;
229
+
230
+ await handler ( getReq . req , getReq . res ) ;
231
+
232
+ expect ( getReq . res . _getStatusCode ( ) ) . toBe ( 200 ) ;
233
+ expect ( getReq . res . _getJSONData ( ) ) . toEqual ( [ "updated-1" , "updated-2" ] ) ;
184
234
} ) ;
185
235
} ) ;
186
236
} ) ;
0 commit comments