it('should failed if no CALDAV_URL', async () => { configEnv.gladys.variable.getValue .withArgs('CALDAV_URL', '5d6c666f-56be-4929-9104-718a78556844', userId) .returns(undefined); configEnv.gladys.variable.getValue .withArgs('CALDAV_USERNAME', '5d6c666f-56be-4929-9104-718a78556844', userId) .returns('tony'); configEnv.gladys.variable.getValue .withArgs('CALDAV_PASSWORD', '5d6c666f-56be-4929-9104-718a78556844', userId) .returns('12345'); await expect(configEnv.config(userId)).to.be.rejectedWith(Error, 'MISSING_PARAMETERS'); });
describe('#createNetwork', () => { it('should merge name correctly into opts', () => { const stub = sinon.stub(landerode, 'createNetwork') .usingPromise(Promise) .resolves(); return landerode.createNet('elthree', {}).then(() => { // for some reason should/expect doesn't work here... stub.calledWith({Name: 'elthree'}); stub.restore(); }); }); it('should throw an error if can\'t create network', () => { const stub = sinon.stub(landerode, 'createNetwork').rejects('Too Many Capes'); return landerode.createNet('hardtimes').should.be.rejectedWith('Too Many Capes') .then(() => { stub.restore(); }); }); });
it('should failed fetch calendars', async () => { sync.gladys.variable.getValue .withArgs('CALDAV_HOST', '5d6c666f-56be-4929-9104-718a78556844', userId) .returns('other'); sync.gladys.variable.getValue .withArgs('CALDAV_HOME_URL', '5d6c666f-56be-4929-9104-718a78556844', userId) .returns('https://caldav.host.com/home'); sync.gladys.variable.getValue .withArgs('CALDAV_USERNAME', '5d6c666f-56be-4929-9104-718a78556844', userId) .returns('tony'); sync.gladys.variable.getValue .withArgs('CALDAV_PASSWORD', '5d6c666f-56be-4929-9104-718a78556844', userId) .returns('12345'); sync.requestCalendars.rejects(); await expect(sync.syncUserCalendars(userId)).to.be.rejectedWith(Error, 'CALDAV_FAILED_REQUEST_CALENDARS'); });
.returns('request2'); await expect(configEnv.config(userId)).to.be.rejectedWith(Error, 'CALDAV_BAD_SETTINGS_HOME_URL'); });
await expect(sync.syncUserCalendars(userId)).to.be.rejectedWith(Error, 'CALDAV_FAILED_REQUEST_CHANGES'); });
context("when a response promise is rejected", function() { it("reports failure", function() { testApp.intent("airportInfoIntent", {}, function(req, res) { return Promise.reject(new Error("whoops")); }); var subject = testApp.request(mockRequest); return expect(subject).to.be.rejectedWith("Unhandled exception: whoops."); }); });
it('should failed to get CALDAV_PRINCIPAL_URL', async () => { configEnv.gladys.variable.getValue .withArgs('CALDAV_URL', '5d6c666f-56be-4929-9104-718a78556844', userId) .returns('https://caldav.host.com'); configEnv.gladys.variable.getValue .withArgs('CALDAV_USERNAME', '5d6c666f-56be-4929-9104-718a78556844', userId) .returns('tony'); configEnv.gladys.variable.getValue .withArgs('CALDAV_PASSWORD', '5d6c666f-56be-4929-9104-718a78556844', userId) .returns('12345'); send.withArgs('request1', 'https://caldav.host.com').rejects(); configEnv.dav.request.propfind .withArgs({ props: [{ name: 'current-user-principal', namespace: namespace.DAV }], depth: 0, mergeResponses: true, }) .returns('request1'); await expect(configEnv.config(userId)).to.be.rejectedWith(Error, 'CALDAV_BAD_SETTINGS_PRINCIPAL_URL'); });
context("when an exception occurs", function() { it("reports failure", function() { testApp.intent("airportInfoIntent", {}, function(req, res) { throw new Error("whoops"); }); var subject = testApp.request(mockRequest); return expect(subject).to.be.rejectedWith("Unhandled exception: whoops."); }); });
}); return testApp.request(mockRequest).should.be.rejectedWith("whoops"); });
return expect(subject).to.be.rejectedWith("promise failure"); }); });
return expect(subject).to.be.rejectedWith("promise failure"); }); });
await expect(sync.syncUserCalendars(userId)).to.be.rejectedWith(Error, 'CALDAV_FAILED_REQUEST_EVENTS'); });
it('should failed if no CALDAV_HOST', async () => { sync.gladys.variable.getValue .withArgs('CALDAV_HOST', '5d6c666f-56be-4929-9104-718a78556844', userId) .returns(undefined); sync.gladys.variable.getValue .withArgs('CALDAV_HOME_URL', '5d6c666f-56be-4929-9104-718a78556844', userId) .returns('https://caldav.host.com/home'); sync.gladys.variable.getValue .withArgs('CALDAV_USERNAME', '5d6c666f-56be-4929-9104-718a78556844', userId) .returns('tony'); sync.gladys.variable.getValue .withArgs('CALDAV_PASSWORD', '5d6c666f-56be-4929-9104-718a78556844', userId) .returns('12345'); await expect(sync.syncUserCalendars(userId)).to.be.rejectedWith(Error, 'CALDAV_NOT_CONFIGURED'); });
/* Self-contained simple unit tests */ describe('createCloudantService', () => { it('should throw InvalidServiceCredentials when credentials are invalid', () => { return expect(dscClient.createCloudantService({name: 'asd', username:'user', password: 'pass'})) .to.be.rejectedWith(errors.InvalidServiceCredentials); }); });
it("should return an error if no Access Token is present", function (done) { var es = new EventSearch(); es.search({ "lat": 40.710803, "lng": -73.964040, "distance": 100 }).should.be.rejectedWith({ "message": "Please specify the lat and lng parameters!", "code": 1 }).and.notify(done); });