Skip to content

Commit c2dcac8

Browse files
bflorianrossiam
authored andcommitted
feat: Added options to apps list method
1 parent db85732 commit c2dcac8

File tree

7 files changed

+490
-5
lines changed

7 files changed

+490
-5
lines changed

src/endpoint/apps.ts

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,11 @@ export interface AppSettings {
210210
settings?: { [key: string]: string }
211211
}
212212

213+
export interface AppListOptions {
214+
appType?: AppType
215+
classification?: AppClassification | AppClassification[]
216+
tag?: { [key: string]: string }
217+
}
213218
export class AppsEndpoint extends Endpoint {
214219

215220
constructor(config: EndpointClientConfig) {
@@ -219,8 +224,20 @@ export class AppsEndpoint extends Endpoint {
219224
/**
220225
* Returns a list of all apps belonging to the principal (i.e. the user)
221226
*/
222-
public async list(): Promise<App[]> {
223-
return this.client.getPagedItems<App>()
227+
public async list(options: AppListOptions = {}): Promise<App[]> {
228+
const params: HttpClientParams = {}
229+
if ('appType' in options && options.appType) {
230+
params.appType = options.appType
231+
}
232+
if ('classification' in options && options.classification) {
233+
params.classification = options.classification
234+
}
235+
if ('tag' in options && options.tag) {
236+
for (const key of Object.keys(options.tag)) {
237+
params[`tag:${key}`] = options.tag[key]
238+
}
239+
}
240+
return this.client.getPagedItems<App>(undefined, params)
224241
}
225242

226243
/**

test/unit/apps.test.ts

Lines changed: 40 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,23 @@
11
import axios from '../../__mocks__/axios'
22
import {
3-
BearerTokenAuthenticator,
4-
SmartThingsClient,
53
App,
4+
AppClassification,
65
AppCreationResponse,
6+
AppOAuth,
7+
AppType,
8+
BearerTokenAuthenticator,
9+
Count,
10+
SignatureType,
11+
SmartThingsClient,
712
Status,
8-
SuccessStatusValue, AppOAuth, Count, SignatureType,
13+
SuccessStatusValue,
914
} from '../../src'
1015
import {expectedRequest} from './helpers/utils'
1116
import list from './data/apps/get_apps'
17+
import listAutomations from './data/apps/get_apps_automation'
18+
import listLambdaAutomations from './data/apps/get_apps_lambda_automations'
19+
import listWebhooks from './data/apps/get_apps_webhook'
20+
import listTags from './data/apps/get_apps_tags'
1221
import get from './data/apps/get_apps_sdktest-234-1582991474199'
1322
import post from './data/apps/post_apps_requireConfirmation=false&signatureType=APP_RSA'
1423
import putSignature from './data/apps/put_apps_a01c0ba4-3ac2-4a5c-9628-c43e394c1ea2_signature-type'
@@ -25,12 +34,40 @@ describe('Apps', () => {
2534
})
2635

2736
it('List', async () => {
37+
axios.request.mockImplementationOnce(() => Promise.resolve({ status: 200, data: listAutomations.response}))
38+
const response: App[] = await client.apps.list({classification: AppClassification.AUTOMATION})
39+
expect(axios.request).toHaveBeenCalledWith(expectedRequest(listAutomations.request))
40+
expect(response).toBe(listAutomations.response.items)
41+
})
42+
43+
it('List Automations', async () => {
2844
axios.request.mockImplementationOnce(() => Promise.resolve({ status: 200, data: list.response}))
2945
const response: App[] = await client.apps.list()
3046
expect(axios.request).toHaveBeenCalledWith(expectedRequest(list.request))
3147
expect(response).toBe(list.response.items)
3248
})
3349

50+
it('List Webhooks', async () => {
51+
axios.request.mockImplementationOnce(() => Promise.resolve({ status: 200, data: listWebhooks.response}))
52+
const response: App[] = await client.apps.list({appType: AppType.WEBHOOK_SMART_APP})
53+
expect(axios.request).toHaveBeenCalledWith(expectedRequest(listWebhooks.request))
54+
expect(response).toBe(listWebhooks.response.items)
55+
})
56+
57+
it('List Lambda Automations', async () => {
58+
axios.request.mockImplementationOnce(() => Promise.resolve({ status: 200, data: listLambdaAutomations.response}))
59+
const response: App[] = await client.apps.list({appType: AppType.LAMBDA_SMART_APP, classification: AppClassification.AUTOMATION})
60+
expect(axios.request).toHaveBeenCalledWith(expectedRequest(listLambdaAutomations.request))
61+
expect(response).toBe(listLambdaAutomations.response.items)
62+
})
63+
64+
it('List Tags', async () => {
65+
axios.request.mockImplementationOnce(() => Promise.resolve({ status: 200, data: listTags.response}))
66+
const response: App[] = await client.apps.list({tag: {industry: 'energy', region: 'North America'}})
67+
expect(axios.request).toHaveBeenCalledWith(expectedRequest(listTags.request))
68+
expect(response).toBe(listTags.response.items)
69+
})
70+
3471
it('Get', async () => {
3572
axios.request.mockImplementationOnce(() => Promise.resolve({ status: 200, data: get.response }))
3673
const response: App = await client.apps.get('sdktest-234-1582991474199')

test/unit/data/apps/get_apps.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ const request = {
66
'Accept': 'application/json',
77
'Authorization': 'Bearer 52991afa-66e8-4af0-8d85-5c568ed5ba7d',
88
},
9+
'params': {},
910
}
1011
const response = {
1112
'items': [
Lines changed: 146 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,146 @@
1+
const request = {
2+
'url': 'https://api.smartthings.com/apps',
3+
'method': 'get',
4+
'headers': {
5+
'Content-Type': 'application/json;charset=utf-8',
6+
'Accept': 'application/json',
7+
'Authorization': 'Bearer 52991afa-66e8-4af0-8d85-5c568ed5ba7d',
8+
},
9+
'params': {'classification': 'AUTOMATION'},
10+
}
11+
const response = {
12+
'items': [
13+
{
14+
'appName': 'bob-florian-scene-control-test-20191014',
15+
'appId': '7941981b-91aa-451d-b063-da30ea0a775c',
16+
'appType': 'API_ONLY',
17+
'classifications': [
18+
'AUTOMATION',
19+
],
20+
'displayName': 'Simple API App Example',
21+
'description': 'Demonstrates basics of a SmartThings API app which authenticates with the SmartThings platform using OAuth2',
22+
'iconImage': {},
23+
'createdDate': '2019-10-14T16:47:31Z',
24+
'lastUpdatedDate': '2019-10-14T16:47:31Z',
25+
},
26+
{
27+
'appName': 'bob-sa-sdk-latency-v1',
28+
'appId': '997d4193-d768-4425-a334-78c34240785f',
29+
'appType': 'LAMBDA_SMART_APP',
30+
'classifications': [
31+
'AUTOMATION',
32+
],
33+
'displayName': 'SA SDK Latency V1',
34+
'description': 'Simple switch reflector',
35+
'iconImage': {},
36+
'createdDate': '2020-02-24T18:20:57Z',
37+
'lastUpdatedDate': '2020-02-24T18:20:57Z',
38+
},
39+
{
40+
'appName': 'bob-sa-sdk-latency-v2',
41+
'appId': 'd9a6049d-06a0-4bb5-a1a8-dc47c70f2a4c',
42+
'appType': 'LAMBDA_SMART_APP',
43+
'classifications': [
44+
'AUTOMATION',
45+
],
46+
'displayName': 'SA SDK Latency V2',
47+
'description': 'Simple switch reflector',
48+
'iconImage': {},
49+
'createdDate': '2020-02-24T18:21:36Z',
50+
'lastUpdatedDate': '2020-02-24T18:21:37Z',
51+
},
52+
{
53+
'appName': 'demohouse-1567481665364-257',
54+
'appId': '5598193a-bcd0-418e-bd8c-0de19d87a952',
55+
'appType': 'LAMBDA_SMART_APP',
56+
'classifications': [
57+
'AUTOMATION',
58+
],
59+
'displayName': 'Demo House',
60+
'description': 'Description',
61+
'iconImage': {},
62+
'createdDate': '2019-09-03T03:34:26Z',
63+
'lastUpdatedDate': '2019-11-20T01:13:43Z',
64+
},
65+
{
66+
'appName': 'demohousestaging-1575906765074-428',
67+
'appId': '190ad0af-9d92-4c1c-9015-afb9a0a7f272',
68+
'appType': 'LAMBDA_SMART_APP',
69+
'classifications': [
70+
'AUTOMATION',
71+
],
72+
'displayName': 'Demo House (staging)',
73+
'description': 'Description',
74+
'iconImage': {},
75+
'createdDate': '2019-12-09T15:52:45Z',
76+
'lastUpdatedDate': '2019-12-10T12:42:00Z',
77+
},
78+
{
79+
'appName': 'smartfloorplan-1579465520512-787',
80+
'appId': 'e35ab7dc-af72-4599-875a-61dcf8c00d15',
81+
'appType': 'LAMBDA_SMART_APP',
82+
'classifications': [
83+
'AUTOMATION',
84+
],
85+
'displayName': 'Smart Floor Plan',
86+
'description': 'Provides IoT device status and control on a floor plan of your home',
87+
'iconImage': {},
88+
'createdDate': '2020-01-19T20:25:21Z',
89+
'lastUpdatedDate': '2020-01-19T20:25:21Z',
90+
},
91+
{
92+
'appName': 'temp-test-lambda-app-abc123',
93+
'appId': '07e24fd4-6aec-4f2a-be1e-3b29da92885e',
94+
'appType': 'LAMBDA_SMART_APP',
95+
'classifications': [
96+
'AUTOMATION',
97+
],
98+
'displayName': 'Temporary Test Lambda App',
99+
'description': 'A temporary test app',
100+
'iconImage': {},
101+
'createdDate': '2020-01-14T23:55:34Z',
102+
'lastUpdatedDate': '2020-01-14T23:55:35Z',
103+
},
104+
{
105+
'appName': 'sa-sdk-functional-switch-reflector',
106+
'appId': '1c593873-ef7d-4665-8f0d-e1da25861e02',
107+
'appType': 'WEBHOOK_SMART_APP',
108+
'classifications': [
109+
'AUTOMATION',
110+
],
111+
'displayName': 'Functional Test Switch Reflector',
112+
'description': 'Mirrors the state of one switch in another switch',
113+
'iconImage': {},
114+
'createdDate': '2020-02-27T14:46:49Z',
115+
'lastUpdatedDate': '2020-02-27T14:46:50Z',
116+
},
117+
{
118+
'appName': 'sdktest-234-1582991474199',
119+
'appId': '2778eb84-2880-47c6-a863-2a4801d7222c',
120+
'appType': 'WEBHOOK_SMART_APP',
121+
'classifications': [
122+
'AUTOMATION',
123+
],
124+
'displayName': 'zzz SDK Functional Test App 1582991474199',
125+
'description': 'Created by SDK functional testing',
126+
'iconImage': {},
127+
'createdDate': '2020-02-29T15:51:14Z',
128+
'lastUpdatedDate': '2020-02-29T15:51:15Z',
129+
},
130+
{
131+
'appName': 'temperatureindicator-1573489391827-189',
132+
'appId': 'a6193eb0-479f-4087-b96d-a80c87150647',
133+
'appType': 'WEBHOOK_SMART_APP',
134+
'classifications': [
135+
'AUTOMATION',
136+
],
137+
'displayName': 'Temperature Indicator',
138+
'description': 'Sets the color of a light depending on a temperature',
139+
'iconImage': {},
140+
'createdDate': '2019-11-11T16:23:12Z',
141+
'lastUpdatedDate': '2019-11-11T16:23:13Z',
142+
},
143+
],
144+
'_links': {},
145+
}
146+
export default {request, response}
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
const request = {
2+
'url': 'https://api.smartthings.com/apps',
3+
'method': 'get',
4+
'headers': {
5+
'Content-Type': 'application/json;charset=utf-8',
6+
'Accept': 'application/json',
7+
'Authorization': 'Bearer 52991afa-66e8-4af0-8d85-5c568ed5ba7d',
8+
},
9+
'params': {'appType': 'LAMBDA_SMART_APP', 'classification': 'AUTOMATION'},
10+
}
11+
const response = {
12+
'items': [
13+
{
14+
'appName': 'bob-sa-sdk-latency-v1',
15+
'appId': '997d4193-d768-4425-a334-78c34240785f',
16+
'appType': 'LAMBDA_SMART_APP',
17+
'classifications': [
18+
'AUTOMATION',
19+
],
20+
'displayName': 'SA SDK Latency V1',
21+
'description': 'Simple switch reflector',
22+
'iconImage': {},
23+
'createdDate': '2020-02-24T18:20:57Z',
24+
'lastUpdatedDate': '2020-02-24T18:20:57Z',
25+
},
26+
{
27+
'appName': 'bob-sa-sdk-latency-v2',
28+
'appId': 'd9a6049d-06a0-4bb5-a1a8-dc47c70f2a4c',
29+
'appType': 'LAMBDA_SMART_APP',
30+
'classifications': [
31+
'AUTOMATION',
32+
],
33+
'displayName': 'SA SDK Latency V2',
34+
'description': 'Simple switch reflector',
35+
'iconImage': {},
36+
'createdDate': '2020-02-24T18:21:36Z',
37+
'lastUpdatedDate': '2020-02-24T18:21:37Z',
38+
},
39+
{
40+
'appName': 'demohouse-1567481665364-257',
41+
'appId': '5598193a-bcd0-418e-bd8c-0de19d87a952',
42+
'appType': 'LAMBDA_SMART_APP',
43+
'classifications': [
44+
'AUTOMATION',
45+
],
46+
'displayName': 'Demo House',
47+
'description': 'Description',
48+
'iconImage': {},
49+
'createdDate': '2019-09-03T03:34:26Z',
50+
'lastUpdatedDate': '2019-11-20T01:13:43Z',
51+
},
52+
{
53+
'appName': 'demohousestaging-1575906765074-428',
54+
'appId': '190ad0af-9d92-4c1c-9015-afb9a0a7f272',
55+
'appType': 'LAMBDA_SMART_APP',
56+
'classifications': [
57+
'AUTOMATION',
58+
],
59+
'displayName': 'Demo House (staging)',
60+
'description': 'Description',
61+
'iconImage': {},
62+
'createdDate': '2019-12-09T15:52:45Z',
63+
'lastUpdatedDate': '2019-12-10T12:42:00Z',
64+
},
65+
{
66+
'appName': 'smartfloorplan-1579465520512-787',
67+
'appId': 'e35ab7dc-af72-4599-875a-61dcf8c00d15',
68+
'appType': 'LAMBDA_SMART_APP',
69+
'classifications': [
70+
'AUTOMATION',
71+
],
72+
'displayName': 'Smart Floor Plan',
73+
'description': 'Provides IoT device status and control on a floor plan of your home',
74+
'iconImage': {},
75+
'createdDate': '2020-01-19T20:25:21Z',
76+
'lastUpdatedDate': '2020-01-19T20:25:21Z',
77+
},
78+
{
79+
'appName': 'temp-test-lambda-app-abc123',
80+
'appId': '07e24fd4-6aec-4f2a-be1e-3b29da92885e',
81+
'appType': 'LAMBDA_SMART_APP',
82+
'classifications': [
83+
'AUTOMATION',
84+
],
85+
'displayName': 'Temporary Test Lambda App',
86+
'description': 'A temporary test app',
87+
'iconImage': {},
88+
'createdDate': '2020-01-14T23:55:34Z',
89+
'lastUpdatedDate': '2020-01-14T23:55:35Z',
90+
},
91+
],
92+
'_links': {},
93+
}
94+
export default {request, response}

0 commit comments

Comments
 (0)