Skip to content

Commit

Permalink
test: test for rejectWith proper error message
Browse files Browse the repository at this point in the history
  • Loading branch information
simon-scherzinger committed Feb 21, 2017
1 parent 9a4a0b8 commit 3f10251
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 27 deletions.
38 changes: 23 additions & 15 deletions test/Account.test.js
Expand Up @@ -66,7 +66,8 @@ describe('Accounts class', () => {
});
});
it('should be rejected on list only with accountID', () => {
return new Accounts().accountList({ accountID: 'id' }).should.be.rejectedWith(Error);
return new Accounts().accountList({ accountID: 'id' })
.should.be.rejectedWith('Providing only an accountID in AccountList filter will result in single resource response. Please use Accounts#get');
});
it('should return resource on get', () => {
const accounts = new Accounts('live');
Expand All @@ -84,7 +85,7 @@ describe('Accounts class', () => {
});
});
it('should be rejected on get in undefiend id', () => {
return new Accounts().account().should.be.rejectedWith(Error);
return new Accounts().account().should.be.rejectedWith('accountID must be defined');
});
it('should return resource on me', () => {
const accounts = new Accounts('live');
Expand Down Expand Up @@ -119,7 +120,7 @@ describe('Accounts class', () => {
.and.notify(() => stub.restore());
});
it('should be rejected on undefined email', () => {
return new Accounts().emailAvailable().should.be.rejectedWith(Error);
return new Accounts().emailAvailable().should.be.rejectedWith('email must be defined');
});
it('should signup new account', () => {
const accounts = new Accounts();
Expand All @@ -145,15 +146,18 @@ describe('Accounts class', () => {
});
});
it('should be rejected on undefined email', () => {
return new Accounts().signup(null, 'supersecure').should.be.rejectedWith(Error);
return new Accounts().signup(null, 'supersecure')
.should.be.rejectedWith('email must be defined');
});
it('should be rejected on undefined password', () => {
return new Accounts().signup('someone@example.com', null).should.be.rejectedWith(Error);
return new Accounts().signup('someone@example.com', null)
.should.be.rejectedWith('password must be defined');
});
it('should be rejected on undefined clientID', () => {
const accounts = new Accounts();
accounts.tokenStore.clientID = undefined;
return accounts.signup('someone@example.com', 'supersecure').should.be.rejectedWith(Error);
return accounts.signup('someone@example.com', 'supersecure')
.should.be.rejectedWith('clientID must be set with Account#setClientID');
});
it('should reset password', () => {
const accounts = new Accounts();
Expand All @@ -171,12 +175,13 @@ describe('Accounts class', () => {
});
});
it('should be rejected on undefined email', () => {
return new Accounts().resetPassword().should.be.rejectedWith(Error);
return new Accounts().resetPassword().should.be.rejectedWith('email must be defined');
});
it('should be rejected on undefiend clientID', () => {
const accounts = new Accounts();
accounts.tokenStore.clientID = undefined;
return new Accounts().resetPassword('someone@entrecode.de').should.be.rejectedWith(Error);
return new Accounts().resetPassword('someone@entrecode.de')
.should.be.rejectedWith('clientID must be set with Account#setClientID');
});
it('should change email', () => {
const accounts = new Accounts();
Expand All @@ -194,15 +199,15 @@ describe('Accounts class', () => {
});
});
it('should be rejected on undefined email', () => {
return new Accounts().changeEmail().should.be.rejectedWith(Error);
return new Accounts().changeEmail().should.be.rejectedWith('email must be defined');
});
it('should be rejected on undefiend token', () => {
const reject = () => {
const accounts = new Accounts();
accounts.tokenStore.del();
return accounts.changeEmail('someone@entrecode.de');
};
return reject().should.be.rejectedWith(Error);
return reject().should.be.rejectedWith('not logged in');
});
it('should create invites', () => {
const accounts = new Accounts();
Expand Down Expand Up @@ -235,7 +240,8 @@ describe('Accounts class', () => {
});
});
it('should be rejected in count not a number', () => {
return new Accounts().createInvites('notANumber').should.be.rejectedWith(Error);
return new Accounts().createInvites('notANumber')
.should.be.rejectedWith('count must be a number');
});
it('should load invites', () => {
const accounts = new Accounts();
Expand Down Expand Up @@ -268,7 +274,8 @@ describe('Accounts class', () => {
});
});
it('should be rejected on clientList only with clientID', () => {
return new Accounts().clientList({ clientID: 'id' }).should.be.rejectedWith(Error);
return new Accounts().clientList({ clientID: 'id' })
.should.be.rejectedWith('Providing only an clientID in ClientList filter will result in single resource response. Please use Accounts#client');
});
it('should return resource on client', () => {
const accounts = new Accounts('live');
Expand All @@ -286,7 +293,7 @@ describe('Accounts class', () => {
});
});
it('should be rejected on client with undefiend id', () => {
return new Accounts().client().should.be.rejectedWith(Error);
return new Accounts().client().should.be.rejectedWith('clientID must be defined');
});
it('should return invalidPermissionsResource', () => {
const accounts = new Accounts('live');
Expand Down Expand Up @@ -319,7 +326,8 @@ describe('Accounts class', () => {
});
});
it('should be rejected on clientList only with clientID', () => {
return new Accounts().groupList({ groupID: 'id' }).should.be.rejectedWith(Error);
return new Accounts().groupList({ groupID: 'id' })
.should.be.rejectedWith('Providing only an groupID in GroupList filter will result in single resource response. Please use Accounts#groupList');
});
it('should return resource on group', () => {
const accounts = new Accounts('live');
Expand All @@ -337,7 +345,7 @@ describe('Accounts class', () => {
});
});
it('should be rejected on group with undefiend id', () => {
return new Accounts().group().should.be.rejectedWith(Error);
return new Accounts().group().should.be.rejectedWith('groupID must be defined');
});
});

Expand Down
2 changes: 1 addition & 1 deletion test/Core.test.js
Expand Up @@ -399,7 +399,7 @@ describe('Network Helper', () => {
detail: 'title',
});

return helper.superagentFormPost('https://datamanager.entrecode.de', {}).should.be.eventually.rejectedWith(Problem);
return helper.superagentFormPost('https://datamanager.entrecode.de', {}).should.be.rejectedWith(Problem);
});
it('should fire error event', () => {
nock('https://datamanager.entrecode.de')
Expand Down
16 changes: 10 additions & 6 deletions test/DataManager.test.js
Expand Up @@ -48,7 +48,8 @@ describe('DataManager class', () => {
});
});
it('should be rejected on list only with dataManagerID', () => {
return new DataManager('live').dataManagerList({ dataManagerID: 'id' }).should.be.rejectedWith(Error);
return new DataManager('live').dataManagerList({ dataManagerID: 'id' })
.should.be.rejectedWith('Providing only an dataManagerID in DataManagerList filter will result in single resource response. Please use DataManager#get');
});
it('should return resource on get', () => {
const dm = new DataManager('live');
Expand All @@ -66,7 +67,8 @@ describe('DataManager class', () => {
});
});
it('should be rejected on get with undefined id', () => {
return new DataManager('live').dataManager().should.be.rejectedWith(Error);
return new DataManager('live').dataManager()
.should.be.rejectedWith('dataManagerID must be defined');
});
it('should call post on create', () => {
const stub = sinon.stub(helper, 'post');
Expand Down Expand Up @@ -96,7 +98,8 @@ describe('DataManager class', () => {
});
});
it('should be rejected on create with undefined', () => {
return new DataManager('live').create().should.be.rejectedWith(Error);
return new DataManager('live').create()
.should.be.rejectedWith('Cannot create resource with undefined object');
});
});

Expand Down Expand Up @@ -229,10 +232,11 @@ describe('DataManager Resource', () => {
.catch(() => stub.restore());
});
it('should throw on model list filtered with modelID', () => {
return resource.modelList({ modelID: 'id' }).should.be.rejectedWith(Error);
return resource.modelList({ modelID: 'id' })
.should.be.rejectedWith('Cannot filter modelList only by dataManagerID and modelID. Use DataManagerResource#model() instead');
});
it('should be rejected on model list filtered with modelID and dataManagerID', () => {
return resource.modelList({ modelID: 'id' }).should.be.rejectedWith(Error);
return resource.modelList({ modelID: 'id' }).should.be.rejectedWith('Cannot filter modelList only by dataManagerID and modelID. Use DataManagerResource#model() instead');
});
it('should load model resource', () => {
const stub = sinon.stub(helper, 'get');
Expand All @@ -246,6 +250,6 @@ describe('DataManager Resource', () => {
.catch(() => stub.restore());
});
it('should be rejected on undefined modelID', () => {
return resource.model().should.be.rejectedWith(Error);
return resource.model().should.be.rejectedWith('modelID must be defined');
});
});
10 changes: 5 additions & 5 deletions test/Session.test.js
Expand Up @@ -53,25 +53,25 @@ describe('Session class', () => {
session.tokenStore.set('eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJlbnRyZWNvZGVUZXN0IiwiaWF0IjoxNDg1NzgzNTg4LCJleHAiOjQ2NDE0NTcxODgsImF1ZCI6IlRlc3QiLCJzdWIiOiJ0ZXN0QGVudHJlY29kZS5kZSJ9.Vhrq5GR2hNz-RoAhdlnIIWHelPciBPCemEa74s7cXn8');
session.setClientID('rest');

return new Session().login('user', 'mysecret').should.be.rejectedWith(Error);
return new Session().login('user', 'mysecret').should.be.rejectedWith('already logged in or old token present. logout first');
});
it('should be rejected on unset clientID', () => {
const session = new Session();
session.tokenStore.del();
session.tokenStore.clientID = undefined;
return session.login('user', 'mysecret').should.be.rejectedWith(Error);
return session.login('user', 'mysecret').should.be.rejectedWith('clientID must be set with Account#setClientID');
});
it('should be rejected on undefined email', () => {
const session = new Session();
session.tokenStore.del();
session.setClientID('rest');
return session.login(null, 'mysecret').should.be.rejectedWith(Error);
return session.login(null, 'mysecret').should.be.rejectedWith('email must be defined');
});
it('should be rejected on undefined password', () => {
const session = new Session();
session.tokenStore.del();
session.setClientID('rest');
return session.setClientID('rest').login('user', null).should.be.rejectedWith(Error);
return session.setClientID('rest').login('user', null).should.be.rejectedWith('password must be defined');
});
it('should logout successfully', () => {
const session = new Session();
Expand All @@ -90,6 +90,6 @@ describe('Session class', () => {
const session = new Session();
session.tokenStore.set('eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJlbnRyZWNvZGVUZXN0IiwiaWF0IjoxNDg1NzgzNTg4LCJleHAiOjQ2NDE0NTcxODgsImF1ZCI6IlRlc3QiLCJzdWIiOiJ0ZXN0QGVudHJlY29kZS5kZSJ9.Vhrq5GR2hNz-RoAhdlnIIWHelPciBPCemEa74s7cXn8');
session.tokenStore.clientID = undefined;
return session.logout().should.be.rejectedWith(Error);
return session.logout().should.be.rejectedWith('clientID must be set with Account#setClientID');
});
});

0 comments on commit 3f10251

Please sign in to comment.