-
Notifications
You must be signed in to change notification settings - Fork 4
/
keylight.test.js
43 lines (37 loc) · 1.15 KB
/
keylight.test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
const axios = require('axios');
const keylight = require('./keylight');
const keylightService = {
ip: '10.10.10.10',
port: 1234
}
const expectedUrl = `http://${keylightService.ip}:${keylightService.port}/elgato/lights`;
jest.mock('axios');
describe('toggleKeyLight', () => {
beforeEach(() => {
axios.put.mockImplementationOnce(() => Promise.resolve(true));
});
describe('when light is off', () => {
beforeEach(() => {
const response = {
data: { lights: [{ on: 0, brightness: 10, temperature: 255 }] }
}
axios.get.mockResolvedValue(response);
});
it('turns the light on', async() => {
await keylight(keylightService);
expect(axios.put).toHaveBeenCalledWith(expectedUrl, {"Lights": [{"On": 1}]});
});
});
describe('when light is on', () => {
beforeEach(() => {
const response = {
data: { lights: [{ on: 1, brightness: 10, temperature: 255 }] }
}
axios.get.mockResolvedValue(response);
});
it('turns the light on', async() => {
await keylight(keylightService);
expect(axios.put).toHaveBeenCalledWith(expectedUrl, {"Lights": [{"On": 0}]});
});
});
});