|
| 1 | +const SmartApp = require('../../lib/smart-app') |
| 2 | + |
| 3 | +describe('smartapp-initialize-spec', () => { |
| 4 | + test('default handler', async () => { |
| 5 | + const app = new SmartApp() |
| 6 | + .appId('xxx') |
| 7 | + .firstPageId('page1') |
| 8 | + .permissions(['r:devices:*']) |
| 9 | + .disableCustomDisplayName(true) |
| 10 | + .disableRemoveApp(true) |
| 11 | + |
| 12 | + // Initialize configuration callback |
| 13 | + const resp = await app.handleMockCallback({ |
| 14 | + lifecycle: 'CONFIGURATION', |
| 15 | + executionId: 'e6903fe6-f88f-da69-4c12-e2802606ccbc', |
| 16 | + locale: 'en', |
| 17 | + version: '0.1.0', |
| 18 | + client: { |
| 19 | + os: 'ios', |
| 20 | + version: '0.0.0', |
| 21 | + language: 'en-US' |
| 22 | + }, |
| 23 | + configurationData: { |
| 24 | + installedAppId: '7d7fa36d-0ad9-4893-985c-6b75858e38e4', |
| 25 | + phase: 'INITIALIZE', |
| 26 | + pageId: '', |
| 27 | + previousPageId: '', |
| 28 | + config: {} |
| 29 | + }, |
| 30 | + settings: {} |
| 31 | + }) |
| 32 | + |
| 33 | + const expectedInitResponse = {initialize: { |
| 34 | + id: 'xxx', |
| 35 | + firstPageId: 'page1', |
| 36 | + permissions: ['r:devices:*'], |
| 37 | + disableCustomDisplayName: true, |
| 38 | + disableRemoveApp: true |
| 39 | + }} |
| 40 | + |
| 41 | + expect(resp.configurationData).toStrictEqual(expectedInitResponse) |
| 42 | + }) |
| 43 | + |
| 44 | + test('custom handler page', async () => { |
| 45 | + const app = new SmartApp() |
| 46 | + .appId('xxx') |
| 47 | + .permissions(['r:devices:*']) |
| 48 | + .initialized((ctx, initialization) => { |
| 49 | + initialization.firstPageId('page2A') |
| 50 | + }) |
| 51 | + |
| 52 | + // Initialize configuration callback |
| 53 | + const resp = await app.handleMockCallback({ |
| 54 | + lifecycle: 'CONFIGURATION', |
| 55 | + executionId: 'e6903fe6-f88f-da69-4c12-e2802606ccbc', |
| 56 | + locale: 'en', |
| 57 | + version: '0.1.0', |
| 58 | + client: { |
| 59 | + os: 'ios', |
| 60 | + version: '0.0.0', |
| 61 | + language: 'en-US' |
| 62 | + }, |
| 63 | + configurationData: { |
| 64 | + installedAppId: '7d7fa36d-0ad9-4893-985c-6b75858e38e4', |
| 65 | + phase: 'INITIALIZE', |
| 66 | + pageId: '', |
| 67 | + previousPageId: '', |
| 68 | + config: {} |
| 69 | + }, |
| 70 | + settings: {} |
| 71 | + }) |
| 72 | + |
| 73 | + const expectedInitResponse = {initialize: { |
| 74 | + id: 'xxx', |
| 75 | + firstPageId: 'page2A', |
| 76 | + permissions: ['r:devices:*'], |
| 77 | + disableCustomDisplayName: false, |
| 78 | + disableRemoveApp: false |
| 79 | + }} |
| 80 | + |
| 81 | + expect(resp.configurationData).toStrictEqual(expectedInitResponse) |
| 82 | + }) |
| 83 | + |
| 84 | + test('custom handler all', async () => { |
| 85 | + const app = new SmartApp() |
| 86 | + .appId('xxx') |
| 87 | + .firstPageId('page1') |
| 88 | + .permissions(['r:devices:*']) |
| 89 | + .disableCustomDisplayName(true) |
| 90 | + .disableRemoveApp(true) |
| 91 | + .initialized((ctx, initialization) => { |
| 92 | + initialization.firstPageId('page2') |
| 93 | + .disableCustomDisplayName(false) |
| 94 | + .disableRemoveApp(false) |
| 95 | + .permissions(['r:devices:*', 'x:devices:*']) |
| 96 | + }) |
| 97 | + |
| 98 | + // Initialize configuration callback |
| 99 | + const resp = await app.handleMockCallback({ |
| 100 | + lifecycle: 'CONFIGURATION', |
| 101 | + executionId: 'e6903fe6-f88f-da69-4c12-e2802606ccbc', |
| 102 | + locale: 'en', |
| 103 | + version: '0.1.0', |
| 104 | + client: { |
| 105 | + os: 'ios', |
| 106 | + version: '0.0.0', |
| 107 | + language: 'en-US' |
| 108 | + }, |
| 109 | + configurationData: { |
| 110 | + installedAppId: '7d7fa36d-0ad9-4893-985c-6b75858e38e4', |
| 111 | + phase: 'INITIALIZE', |
| 112 | + pageId: '', |
| 113 | + previousPageId: '', |
| 114 | + config: {} |
| 115 | + }, |
| 116 | + settings: {} |
| 117 | + }) |
| 118 | + |
| 119 | + const expectedInitResponse = {initialize: { |
| 120 | + id: 'xxx', |
| 121 | + firstPageId: 'page2', |
| 122 | + permissions: ['r:devices:*', 'x:devices:*'], |
| 123 | + disableCustomDisplayName: false, |
| 124 | + disableRemoveApp: false |
| 125 | + }} |
| 126 | + |
| 127 | + expect(resp.configurationData).toStrictEqual(expectedInitResponse) |
| 128 | + }) |
| 129 | +}) |
0 commit comments