describe('dashboard.getBySelector', () => { const dashboard = new Dashboard(); it('should return dashboard', async () => { const testDashboard = await dashboard.getBySelector('test-dashboard'); expect(testDashboard).to.have.property('name', 'Test dashboard'); expect(testDashboard).to.have.property('selector', 'test-dashboard'); }); it('should return not found', async () => { const promise = dashboard.getBySelector('not-found-dashboard'); return assert.isRejected(promise, 'Dashboard not found'); }); });
it('should return error, unable to contact third party provider', async () => { const OpenWeatherService = proxyquire('../../../services/openweather/index', brokenAxios); const openWeatherService = OpenWeatherService(gladys, '35deac79-f295-4adf-8512-f2f48e1ea0f8'); await openWeatherService.start(); const promise = openWeatherService.weather.get({ latitude: 12, longitude: 10, }); return assert.isRejected(promise, 'REQUEST_TO_THIRD_PARTY_FAILED'); });
describe('user.forgotPassword', () => { const session = new Session('secret'); const user = new User(session); it('should return access token and refresh token', async () => { const newSession = await user.forgotPassword('demo@demo.com'); expect(newSession).to.have.property('refresh_token'); expect(newSession).to.have.property('access_token'); }); it('should return error, user not found', async () => { const promise = user.forgotPassword('not-found@test.com'); return assert.isRejected(promise, 'User not found'); }); });
describe('room.destroy', () => { const brain = { addRoom: fake.returns(null), removeRoom: fake.returns(null), }; const room = new Room(brain); it('should destroy a room', async () => { await room.destroy('test-room'); assert.calledOnce(brain.removeRoom); }); it('should return room not found', async () => { const promise = room.destroy('room-does-not-exist'); return assertChai.isRejected(promise, 'Room not found'); }); });
describe('SceneManager', () => { it('should destroy a scene', async () => { const sceneManager = new SceneManager({}, event); sceneManager.scenes['test-scene'] = { name: 'Test Scene', triggers: [], }; await sceneManager.destroy('test-scene'); expect(sceneManager.scenes['test-scene']).to.be.undefined; // eslint-disable-line }); it('should return not found', async () => { const sceneManager = new SceneManager({}, event); const promise = sceneManager.destroy('not-found-scene'); return assert.isRejected(promise); }); });
describe('calendar.destroy', () => { const calendar = new Calendar(); it('should destroy a calendar event', async () => { await calendar.destroyEvent('test-calendar-event'); }); it('should return calendar event not found', async () => { const promise = calendar.destroyEvent('not-found-calendar-event'); return assert.isRejected(promise, 'CalendarEvent not found'); }); });
describe('user.getByTelegramUserId', () => { const user = new User(); it('should return user', async () => { const userFound = await user.getByTelegramUserId('555555555'); expect(userFound).to.deep.equal({ id: '0cd30aef-9c4e-4a23-88e3-3547971296e5', language: 'en', }); }); it('should throw notFound error', async () => { const promise = user.getByTelegramUserId('THISDOESNOTEXIST'); return assert.isRejected(promise, 'User with telegram_user_id "THISDOESNOTEXIST" not found'); }); });
describe('SceneManager', () => { it('should get a scene by selector', async () => { const sceneManager = new SceneManager({}, event); const scene = await sceneManager.getBySelector('test-scene'); expect(scene).to.have.property('selector', 'test-scene'); }); it('should return not found', async () => { const sceneManager = new SceneManager({}, event); const promise = sceneManager.getBySelector('not-found-scene'); return assert.isRejected(promise); }); });
describe('house.destroy', () => { const house = new House(event); it('should delete a house', async () => { await house.destroy('test-house'); }); it('should return house not found', async () => { const promise = house.destroy('house-not-found'); return assertChai.isRejected(promise, 'House not found'); }); });
describe('user.getPicture', () => { const session = new Session('secret'); const user = new User(session); it('should get user', async () => { const picture = await user.getPicture('0cd30aef-9c4e-4a23-88e3-3547971296e5'); expect(picture).to.equal( 'data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAAAQABAAD/2wBDABALCwsMCxAMDBAXDw0PFxoUEBAUGh4XFxcXFx4dFxoZGRoXHR0jJCYkIx0vLzIyLy9AQEBAQEBAQEBAQEBAQED/2wBDAREPDxETERUSEhUUERMRFBkUFRUUGSUZGRsZGSUvIh0dHR0iLyotJiYmLSo0NC8vNDRAQD5AQEBAQEBAQEBAQED/wAARCAAFAAUDASIAAhEBAxEB/8QAFQABAQAAAAAAAAAAAAAAAAAAAAP/xAAeEAABBAEFAAAAAAAAAAAAAAASAAEDEQITFSExQf/EABUBAQEAAAAAAAAAAAAAAAAAAAME/8QAFxEAAwEAAAAAAAAAAAAAAAAAADGSk//aAAwDAQACEQMRAD8AjjvOpI7PMdRk1YkQSDzd134iIgpluaP/2Q==', ); }); it('should return error, user not found', async () => { const promise = user.getPicture('949735af-cdc5-4ae3-b756-092d174a4092'); return assert.isRejected(promise, 'User not found'); }); });
describe('house.update', () => { const house = new House(event); it('should update a house', async () => { const updatedHouse = await house.update('test-house', { name: 'Updated house', }); expect(updatedHouse).to.have.property('name', 'Updated house'); expect(updatedHouse).to.have.property('selector', 'test-house'); }); it('should return not found', async () => { const promise = house.update('house-does-not-exist', { name: 'Updated house', }); return assertChai.isRejected(promise, 'House not found'); }); });
describe('area.destroy', () => { const area = new Area(); it('should destroy a area', async () => { await area.destroy('test-area'); }); it('should return area not found', async () => { const promise = area.destroy('not-found-area'); return assert.isRejected(promise, 'Area not found'); }); });
describe('dashboard.destroy', () => { const dashboard = new Dashboard(); it('should destroy a dashoard', async () => { await dashboard.destroy('test-dashboard'); }); it('should return not found', async () => { const promise = dashboard.destroy('not-found-dashboard'); return assert.isRejected(promise, 'Dashboard not found'); }); });
describe('dashboard.update', () => { const dashboard = new Dashboard(); it('should update a dashoard', async () => { const updatedDashboard = await dashboard.update('test-dashboard', { name: 'New name', }); expect(updatedDashboard).to.have.property('name', 'New name'); expect(updatedDashboard).to.have.property('selector', 'test-dashboard'); }); it('should return not found', async () => { const promise = dashboard.update('not-found-dashboard', { name: 'new name', }); return assert.isRejected(promise, 'Dashboard not found'); }); });
describe('calendar.destroy', () => { const calendar = new Calendar(); it('should destroy a calendar', async () => { await calendar.destroy('test-calendar'); }); it('should return calendar not found', async () => { const promise = calendar.destroy('not-found-calendar'); return assert.isRejected(promise, 'Calendar not found'); }); });