|
1 | | -const assert = require('assert').strict |
2 | 1 | const SmartApp = require('../../lib/smart-app') |
3 | 2 |
|
4 | 3 | describe('smartapp-page-spec', () => { |
| 4 | + let app |
| 5 | + beforeEach(() => { |
| 6 | + app = new SmartApp() |
| 7 | + }) |
| 8 | + |
5 | 9 | it('should set page ID', () => { |
6 | | - const app = new SmartApp() |
7 | 10 | app.appId('xxx') |
8 | 11 | app.page('eaMainPage', (ctx, page) => { |
9 | 12 | page.section('whenDoorOpensAndCloses', section => { |
@@ -56,7 +59,7 @@ describe('smartapp-page-spec', () => { |
56 | 59 | disableRemoveApp: false |
57 | 60 | }} |
58 | 61 |
|
59 | | - assert.deepStrictEqual(initResponse.configurationData, expectedInitResponse) |
| 62 | + expect(initResponse.configurationData).toStrictEqual(expectedInitResponse) |
60 | 63 | }) |
61 | 64 |
|
62 | 65 | // Page configuration callback |
@@ -109,7 +112,8 @@ describe('smartapp-page-spec', () => { |
109 | 112 | ] |
110 | 113 | } |
111 | 114 | } |
112 | | - assert.deepStrictEqual(pageResponse.configurationData, expectedPageResponse) |
| 115 | + |
| 116 | + expect(pageResponse.configurationData).toStrictEqual(expectedPageResponse) |
113 | 117 | }) |
114 | 118 |
|
115 | 119 | // Default page handler configuration callback |
@@ -182,12 +186,12 @@ describe('smartapp-page-spec', () => { |
182 | 186 | ] |
183 | 187 | } |
184 | 188 | } |
185 | | - assert.deepStrictEqual(pageResponse.configurationData, expectedPageResponse) |
| 189 | + |
| 190 | + expect(pageResponse.configurationData).toStrictEqual(expectedPageResponse) |
186 | 191 | }) |
187 | 192 | }) |
188 | 193 |
|
189 | 194 | it('should configure event logger', () => { |
190 | | - const app = new SmartApp() |
191 | 195 | app.appId('xxx') |
192 | 196 | app.enableEventLogging(4) |
193 | 197 | app.page('eaMainPage', (ctx, page) => { |
@@ -218,9 +222,7 @@ describe('smartapp-page-spec', () => { |
218 | 222 | }) |
219 | 223 | }) |
220 | 224 |
|
221 | | - it('default page handler', () => { |
222 | | - const app = new SmartApp() |
223 | | - |
| 225 | + test('default page handler', () => { |
224 | 226 | app.handleMockCallback({ |
225 | 227 | lifecycle: 'CONFIGURATION', |
226 | 228 | executionId: 'abcf6e72-60f4-1f27-341b-449ad9e2192e', |
@@ -263,13 +265,12 @@ describe('smartapp-page-spec', () => { |
263 | 265 | ] |
264 | 266 | } |
265 | 267 | } |
266 | | - assert.deepStrictEqual(pageResponse.configurationData, expectedPageResponse) |
| 268 | + |
| 269 | + expect(pageResponse.configurationData).toStrictEqual(expectedPageResponse) |
267 | 270 | }) |
268 | 271 | }) |
269 | 272 |
|
270 | | - it('default page handler without pageId', () => { |
271 | | - const app = new SmartApp() |
272 | | - |
| 273 | + test('default page handler without pageId', () => { |
273 | 274 | app.handleMockCallback({ |
274 | 275 | lifecycle: 'CONFIGURATION', |
275 | 276 | executionId: 'abcf6e72-60f4-1f27-341b-449ad9e2192e', |
@@ -312,7 +313,37 @@ describe('smartapp-page-spec', () => { |
312 | 313 | ] |
313 | 314 | } |
314 | 315 | } |
315 | | - assert.deepStrictEqual(pageResponse.configurationData, expectedPageResponse) |
| 316 | + |
| 317 | + expect(pageResponse.configurationData).toStrictEqual(expectedPageResponse) |
316 | 318 | }) |
317 | 319 | }) |
| 320 | + |
| 321 | + it('should respond with error when config phase is not supported', async () => { |
| 322 | + const unsupportedConfigPhase = { |
| 323 | + lifecycle: 'CONFIGURATION', |
| 324 | + executionId: '00000000-0000-0000-0000-000000000000', |
| 325 | + locale: 'en', |
| 326 | + version: '0.1.0', |
| 327 | + client: { |
| 328 | + os: 'ios', |
| 329 | + version: '0.0.0', |
| 330 | + language: 'fr' |
| 331 | + }, |
| 332 | + configurationData: { |
| 333 | + installedAppId: '00000000-0000-0000-0000-000000000000', |
| 334 | + phase: 'UNSUPPORTED', |
| 335 | + pageId: '', |
| 336 | + previousPageId: '', |
| 337 | + config: {} |
| 338 | + }, |
| 339 | + settings: {} |
| 340 | + } |
| 341 | + |
| 342 | + const expectedPageResponse = { |
| 343 | + message: 'Server error: \'Error: Unsupported config phase: UNSUPPORTED\'', |
| 344 | + statusCode: 500 |
| 345 | + } |
| 346 | + |
| 347 | + await expect(app.handleMockCallback(unsupportedConfigPhase)).resolves.toStrictEqual(expectedPageResponse) |
| 348 | + }) |
318 | 349 | }) |
0 commit comments