mirror of
https://github.com/n8n-io/n8n.git
synced 2024-12-31 15:37:26 -08:00
test(Philips Hue Node): Add test coverage (no-changelog) (#12223)
This commit is contained in:
parent
1fc9c59a57
commit
de75c7b529
108
packages/nodes-base/nodes/PhilipsHue/test/apiResponses.ts
Normal file
108
packages/nodes-base/nodes/PhilipsHue/test/apiResponses.ts
Normal file
|
@ -0,0 +1,108 @@
|
|||
export const getLightsResponse = {
|
||||
'1': {
|
||||
state: {
|
||||
on: false,
|
||||
bri: 1,
|
||||
hue: 33761,
|
||||
sat: 254,
|
||||
effect: 'none',
|
||||
xy: [0.3171, 0.3366],
|
||||
ct: 159,
|
||||
alert: 'none',
|
||||
colormode: 'xy',
|
||||
mode: 'homeautomation',
|
||||
reachable: true,
|
||||
},
|
||||
swupdate: {
|
||||
state: 'noupdates',
|
||||
lastinstall: '2018-01-02T19:24:20',
|
||||
},
|
||||
type: 'Extended color light',
|
||||
name: 'Hue color lamp 7',
|
||||
modelid: 'LCT007',
|
||||
manufacturername: 'Philips',
|
||||
productname: 'Hue color lamp',
|
||||
capabilities: {
|
||||
certified: true,
|
||||
control: {
|
||||
mindimlevel: 5000,
|
||||
maxlumen: 600,
|
||||
colorgamuttype: 'B',
|
||||
colorgamut: [
|
||||
[0.675, 0.322],
|
||||
[0.409, 0.518],
|
||||
[0.167, 0.04],
|
||||
],
|
||||
ct: {
|
||||
min: 153,
|
||||
max: 500,
|
||||
},
|
||||
},
|
||||
streaming: {
|
||||
renderer: true,
|
||||
proxy: false,
|
||||
},
|
||||
},
|
||||
config: {
|
||||
archetype: 'sultanbulb',
|
||||
function: 'mixed',
|
||||
direction: 'omnidirectional',
|
||||
},
|
||||
uniqueid: '00:17:88:01:00:bd:c7:b9-0b',
|
||||
swversion: '5.105.0.21169',
|
||||
},
|
||||
};
|
||||
|
||||
export const getConfigResponse = {
|
||||
name: 'Philips hue',
|
||||
zigbeechannel: 15,
|
||||
mac: '00:17:88:00:00:00',
|
||||
dhcp: true,
|
||||
ipaddress: '192.168.1.7',
|
||||
netmask: '255.255.255.0',
|
||||
gateway: '192.168.1.1',
|
||||
proxyaddress: 'none',
|
||||
proxyport: 0,
|
||||
UTC: '2014-07-17T09:27:35',
|
||||
localtime: '2014-07-17T11:27:35',
|
||||
timezone: 'Europe/Madrid',
|
||||
whitelist: {
|
||||
ffffffffe0341b1b376a2389376a2389: {
|
||||
'last use date': '2014-07-17T07:21:38',
|
||||
'create date': '2014-04-08T08:55:10',
|
||||
name: 'PhilipsHueAndroidApp#TCT ALCATEL ONE TOU',
|
||||
},
|
||||
pAtwdCV8NZId25Gk: {
|
||||
'last use date': '2014-05-07T18:28:29',
|
||||
'create date': '2014-04-09T17:29:16',
|
||||
name: 'n8n',
|
||||
},
|
||||
},
|
||||
swversion: '01012917',
|
||||
apiversion: '1.3.0',
|
||||
swupdate: {
|
||||
updatestate: 0,
|
||||
url: '',
|
||||
text: '',
|
||||
notify: false,
|
||||
},
|
||||
linkbutton: false,
|
||||
portalservices: false,
|
||||
portalconnection: 'connected',
|
||||
portalstate: {
|
||||
signedon: true,
|
||||
incoming: false,
|
||||
outgoing: true,
|
||||
communication: 'disconnected',
|
||||
},
|
||||
};
|
||||
|
||||
export const updateLightResponse = [
|
||||
{ success: { '/lights/1/state/bri': 200 } },
|
||||
{ success: { '/lights/1/state/on': true } },
|
||||
{ success: { '/lights/1/state/hue': 50000 } },
|
||||
];
|
||||
|
||||
export const deleteLightResponse = {
|
||||
success: '/lights/1 deleted.',
|
||||
};
|
227
packages/nodes-base/nodes/PhilipsHue/test/workflow.json
Normal file
227
packages/nodes-base/nodes/PhilipsHue/test/workflow.json
Normal file
|
@ -0,0 +1,227 @@
|
|||
{
|
||||
"name": "[TEST] Hue",
|
||||
"nodes": [
|
||||
{
|
||||
"parameters": {},
|
||||
"type": "n8n-nodes-base.manualTrigger",
|
||||
"typeVersion": 1,
|
||||
"position": [0, 0],
|
||||
"id": "9e687c5d-e3a5-436d-a96d-7bfde1110f40",
|
||||
"name": "When clicking ‘Test workflow’"
|
||||
},
|
||||
{
|
||||
"parameters": {
|
||||
"operation": "getAll",
|
||||
"returnAll": true
|
||||
},
|
||||
"type": "n8n-nodes-base.philipsHue",
|
||||
"typeVersion": 1,
|
||||
"position": [260, 0],
|
||||
"id": "063bcf31-3055-42f1-904f-d517f85db182",
|
||||
"name": "Philips Hue",
|
||||
"credentials": {
|
||||
"philipsHueOAuth2Api": {
|
||||
"id": "s6tRicNTKQoa9TDq",
|
||||
"name": "PhilipHue account"
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"parameters": {},
|
||||
"type": "n8n-nodes-base.noOp",
|
||||
"typeVersion": 1,
|
||||
"position": [480, 0],
|
||||
"id": "d6c4f99a-d660-4113-aa08-a7bcc9391236",
|
||||
"name": "No Operation, do nothing"
|
||||
},
|
||||
{
|
||||
"parameters": {
|
||||
"lightId": "=1",
|
||||
"additionalFields": {
|
||||
"bri": 200,
|
||||
"hue": 50000
|
||||
}
|
||||
},
|
||||
"type": "n8n-nodes-base.philipsHue",
|
||||
"typeVersion": 1,
|
||||
"position": [260, 200],
|
||||
"id": "c8311112-d24e-4787-80b1-cc5397aea98e",
|
||||
"name": "Philips Hue1",
|
||||
"credentials": {
|
||||
"philipsHueOAuth2Api": {
|
||||
"id": "s6tRicNTKQoa9TDq",
|
||||
"name": "PhilipHue account"
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"parameters": {},
|
||||
"type": "n8n-nodes-base.noOp",
|
||||
"typeVersion": 1,
|
||||
"position": [480, 200],
|
||||
"id": "c438bf28-0cf8-459a-bd3a-28f6c30b3f2f",
|
||||
"name": "No Operation, do nothing1"
|
||||
},
|
||||
{
|
||||
"parameters": {
|
||||
"operation": "delete",
|
||||
"lightId": "=1"
|
||||
},
|
||||
"type": "n8n-nodes-base.philipsHue",
|
||||
"typeVersion": 1,
|
||||
"position": [280, 400],
|
||||
"id": "fd197627-9221-4e6d-ab51-53d262004db8",
|
||||
"name": "Philips Hue2",
|
||||
"credentials": {
|
||||
"philipsHueOAuth2Api": {
|
||||
"id": "s6tRicNTKQoa9TDq",
|
||||
"name": "PhilipHue account"
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"parameters": {},
|
||||
"type": "n8n-nodes-base.noOp",
|
||||
"typeVersion": 1,
|
||||
"position": [500, 400],
|
||||
"id": "19796164-8527-462b-b01b-71d7f60c94af",
|
||||
"name": "No Operation, do nothing2"
|
||||
}
|
||||
],
|
||||
"pinData": {
|
||||
"No Operation, do nothing": [
|
||||
{
|
||||
"json": {
|
||||
"state": {
|
||||
"on": false,
|
||||
"bri": 1,
|
||||
"hue": 33761,
|
||||
"sat": 254,
|
||||
"effect": "none",
|
||||
"xy": [0.3171, 0.3366],
|
||||
"ct": 159,
|
||||
"alert": "none",
|
||||
"colormode": "xy",
|
||||
"mode": "homeautomation",
|
||||
"reachable": true
|
||||
},
|
||||
"swupdate": {
|
||||
"state": "noupdates",
|
||||
"lastinstall": "2018-01-02T19:24:20"
|
||||
},
|
||||
"type": "Extended color light",
|
||||
"name": "Hue color lamp 7",
|
||||
"modelid": "LCT007",
|
||||
"manufacturername": "Philips",
|
||||
"productname": "Hue color lamp",
|
||||
"capabilities": {
|
||||
"certified": true,
|
||||
"control": {
|
||||
"mindimlevel": 5000,
|
||||
"maxlumen": 600,
|
||||
"colorgamuttype": "B",
|
||||
"colorgamut": [[0.675, 0.322], [0.409, 0.518], [0.167, 0.04]],
|
||||
"ct": {
|
||||
"min": 153,
|
||||
"max": 500
|
||||
}
|
||||
},
|
||||
"streaming": {
|
||||
"renderer": true,
|
||||
"proxy": false
|
||||
}
|
||||
},
|
||||
"config": {
|
||||
"archetype": "sultanbulb",
|
||||
"function": "mixed",
|
||||
"direction": "omnidirectional"
|
||||
},
|
||||
"uniqueid": "00:17:88:01:00:bd:c7:b9-0b",
|
||||
"swversion": "5.105.0.21169"
|
||||
}
|
||||
}
|
||||
],
|
||||
"No Operation, do nothing1": [
|
||||
{
|
||||
"json": {
|
||||
"/lights/1/state/bri": 200,
|
||||
"/lights/1/state/on": true,
|
||||
"/lights/1/state/hue": 50000
|
||||
}
|
||||
}
|
||||
],
|
||||
"No Operation, do nothing2": [
|
||||
{
|
||||
"json": {
|
||||
"success": "/lights/1 deleted."
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
"connections": {
|
||||
"When clicking ‘Test workflow’": {
|
||||
"main": [
|
||||
[
|
||||
{
|
||||
"node": "Philips Hue",
|
||||
"type": "main",
|
||||
"index": 0
|
||||
},
|
||||
{
|
||||
"node": "Philips Hue1",
|
||||
"type": "main",
|
||||
"index": 0
|
||||
},
|
||||
{
|
||||
"node": "Philips Hue2",
|
||||
"type": "main",
|
||||
"index": 0
|
||||
}
|
||||
]
|
||||
]
|
||||
},
|
||||
"Philips Hue": {
|
||||
"main": [
|
||||
[
|
||||
{
|
||||
"node": "No Operation, do nothing",
|
||||
"type": "main",
|
||||
"index": 0
|
||||
}
|
||||
]
|
||||
]
|
||||
},
|
||||
"Philips Hue1": {
|
||||
"main": [
|
||||
[
|
||||
{
|
||||
"node": "No Operation, do nothing1",
|
||||
"type": "main",
|
||||
"index": 0
|
||||
}
|
||||
]
|
||||
]
|
||||
},
|
||||
"Philips Hue2": {
|
||||
"main": [
|
||||
[
|
||||
{
|
||||
"node": "No Operation, do nothing2",
|
||||
"type": "main",
|
||||
"index": 0
|
||||
}
|
||||
]
|
||||
]
|
||||
}
|
||||
},
|
||||
"active": false,
|
||||
"settings": {
|
||||
"executionOrder": "v1"
|
||||
},
|
||||
"versionId": "2c19891b-ba8e-4026-b8c2-b5f3f508b54a",
|
||||
"meta": {
|
||||
"instanceId": "0fa937d34dcabeff4bd6480d3b42cc95edf3bc20e6810819086ef1ce2623639d"
|
||||
},
|
||||
"id": "LAngRPRzm3OGrfh0",
|
||||
"tags": []
|
||||
}
|
41
packages/nodes-base/nodes/PhilipsHue/test/workflow.test.ts
Normal file
41
packages/nodes-base/nodes/PhilipsHue/test/workflow.test.ts
Normal file
|
@ -0,0 +1,41 @@
|
|||
import nock from 'nock';
|
||||
|
||||
import {
|
||||
deleteLightResponse,
|
||||
getLightsResponse,
|
||||
getConfigResponse,
|
||||
updateLightResponse,
|
||||
} from './apiResponses';
|
||||
import {
|
||||
setup,
|
||||
equalityTest,
|
||||
workflowToTests,
|
||||
getWorkflowFilenames,
|
||||
} from '../../../test/nodes/Helpers';
|
||||
|
||||
describe('PhilipsHue', () => {
|
||||
describe('Run workflow', () => {
|
||||
const workflows = getWorkflowFilenames(__dirname);
|
||||
const tests = workflowToTests(workflows);
|
||||
|
||||
beforeAll(() => {
|
||||
nock.disableNetConnect();
|
||||
|
||||
const mock = nock('https://api.meethue.com/route');
|
||||
mock.persist().get('/api/0/config').reply(200, getConfigResponse);
|
||||
mock.get('/api/pAtwdCV8NZId25Gk/lights').reply(200, getLightsResponse);
|
||||
mock.put('/api/pAtwdCV8NZId25Gk/lights/1/state').reply(200, updateLightResponse);
|
||||
mock.delete('/api/pAtwdCV8NZId25Gk/lights/1').reply(200, deleteLightResponse);
|
||||
});
|
||||
|
||||
afterAll(() => {
|
||||
nock.restore();
|
||||
});
|
||||
|
||||
const nodeTypes = setup(tests);
|
||||
|
||||
for (const testData of tests) {
|
||||
test(testData.description, async () => await equalityTest(testData, nodeTypes));
|
||||
}
|
||||
});
|
||||
});
|
|
@ -128,4 +128,20 @@ BQIDAQAB
|
|||
notionApi: {
|
||||
apiKey: 'key123',
|
||||
},
|
||||
philipsHueOAuth2Api: {
|
||||
grantType: 'authorizationCode',
|
||||
appId: 'APPID',
|
||||
authUrl: 'https://api.meethue.com/v2/oauth2/authorize',
|
||||
accessTokenUrl: 'https://api.meethue.com/v2/oauth2/token',
|
||||
authQueryParameters: 'appid=APPID',
|
||||
scope: '',
|
||||
authentication: 'header',
|
||||
oauthTokenData: {
|
||||
access_token: 'ACCESSTOKEN',
|
||||
refresh_token: 'REFRESHTOKEN',
|
||||
scope: '',
|
||||
token_type: 'bearer',
|
||||
expires_in: 86400,
|
||||
},
|
||||
},
|
||||
} as const;
|
||||
|
|
Loading…
Reference in a new issue