Skip to content

Commit ba5b8ee

Browse files
authored
Merge pull request #20 from erodewald/10-uninstall-handler-broken
Fix uninstalled() assigning to wrong handler
2 parents 8eb6b3c + f577835 commit ba5b8ee

File tree

3 files changed

+145
-4
lines changed

3 files changed

+145
-4
lines changed

lib/smart-app.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ module.exports = class SmartApp {
161161
/// ////////////
162162

163163
uninstalled(callback) {
164-
this._installedHandler = callback
164+
this._uninstalledHandler = callback
165165
return this
166166
}
167167

test/smartapp-page-spec.js

Lines changed: 62 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
/* eslint no-undef: "off" */
2+
const assert = require('assert').strict
23
const SmartApp = require('../lib/smart-app')
34

45
describe('smartapp-page-spec', () => {
@@ -39,7 +40,7 @@ describe('smartapp-page-spec', () => {
3940
settings: {}
4041
})
4142

42-
const pageReponse = app.handleMockCallback({
43+
const pageResponse = app.handleMockCallback({
4344
lifecycle: 'CONFIGURATION',
4445
executionId: 'abcf6e72-60f4-1f27-341b-449ad9e2192e',
4546
locale: 'en',
@@ -59,8 +60,66 @@ describe('smartapp-page-spec', () => {
5960
settings: {}
6061
})
6162

62-
console.log(JSON.stringify(initResponse, null, 2))
63-
console.log(JSON.stringify(pageReponse, null, 2))
63+
const expectedInitResponse = {initialize: {
64+
id: 'xxx',
65+
firstPageId: 'eaMainPage',
66+
permissions: [],
67+
disableCustomDisplayName: false,
68+
disableRemoveApp: false
69+
}}
70+
71+
const expectedPageResponse = {
72+
page: {
73+
name: 'pages.eaMainPage.name',
74+
complete: true,
75+
pageId: 'eaMainPage',
76+
nextPageId: null,
77+
previousPageId: null,
78+
sections: [
79+
{
80+
name: 'whenDoorOpensAndCloses',
81+
settings: [
82+
{
83+
id: 'contactSensor',
84+
name: 'pages.eaMainPage.settings.contactSensor.name',
85+
required: true,
86+
type: 'DEVICE',
87+
description: 'Tap to set',
88+
multiple: false,
89+
capabilities: [
90+
'contactSensor'
91+
],
92+
permissions: [
93+
'r'
94+
]
95+
}
96+
]
97+
},
98+
{
99+
name: 'turnLightsOnAndOff',
100+
settings: [
101+
{
102+
id: 'lights',
103+
name: 'pages.eaMainPage.settings.lights.name',
104+
required: true,
105+
type: 'DEVICE',
106+
description: 'Tap to set',
107+
multiple: true,
108+
capabilities: [
109+
'switch'
110+
],
111+
permissions: [
112+
'r',
113+
'x'
114+
]
115+
}
116+
]
117+
}
118+
]
119+
}
120+
}
121+
assert.deepStrictEqual(initResponse.configurationData, expectedInitResponse)
122+
assert.deepStrictEqual(pageResponse.configurationData, expectedPageResponse)
64123
})
65124

66125
it('should configure event logger', () => {

test/smartapp-spec.js

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
/* eslint no-undef: "off" */
2+
const assert = require('assert').strict
3+
const SmartApp = require('../lib/smart-app')
4+
5+
describe('smartapp-spec', () => {
6+
let app
7+
let expectedData
8+
let receivedData
9+
10+
beforeEach(() => {
11+
app = new SmartApp()
12+
expectedData = {
13+
authToken: 'string',
14+
refreshToken: 'string',
15+
installedApp: {
16+
installedAppId: 'd692699d-e7a6-400d-a0b7-d5be96e7a564',
17+
locationId: 'e675a3d9-2499-406c-86dc-8a492a886494',
18+
config: {}
19+
}
20+
}
21+
})
22+
23+
it('should handle INSTALL event', () => {
24+
app.installed((_, installData) => {
25+
receivedData = installData
26+
})
27+
app.handleMockCallback({
28+
lifecycle: 'INSTALL',
29+
executionId: 'e6903fe6-f88f-da69-4c12-e2802606ccbc',
30+
locale: 'en',
31+
version: '0.1.0',
32+
client: {
33+
os: 'ios',
34+
version: '0.0.0',
35+
language: 'en-US'
36+
},
37+
installData: expectedData,
38+
settings: {}
39+
})
40+
assert.strictEqual(receivedData, expectedData)
41+
})
42+
43+
it('should handle UNINSTALL event', () => {
44+
app.uninstalled((_, uninstallData) => {
45+
receivedData = uninstallData
46+
})
47+
app.handleMockCallback({
48+
lifecycle: 'UNINSTALL',
49+
executionId: 'e6903fe6-f88f-da69-4c12-e2802606ccbc',
50+
locale: 'en',
51+
version: '0.1.0',
52+
client: {
53+
os: 'ios',
54+
version: '0.0.0',
55+
language: 'en-US'
56+
},
57+
uninstallData: expectedData,
58+
settings: {}
59+
})
60+
assert.strictEqual(receivedData, expectedData)
61+
})
62+
63+
it('should handle UPDATE event', () => {
64+
app.updated((_, updateData) => {
65+
receivedData = updateData
66+
})
67+
app.handleMockCallback({
68+
lifecycle: 'UPDATE',
69+
executionId: 'e6903fe6-f88f-da69-4c12-e2802606ccbc',
70+
locale: 'en',
71+
version: '0.1.0',
72+
client: {
73+
os: 'ios',
74+
version: '0.0.0',
75+
language: 'en-US'
76+
},
77+
updateData: expectedData,
78+
settings: {}
79+
})
80+
assert.strictEqual(receivedData, expectedData)
81+
})
82+
})

0 commit comments

Comments
 (0)