Skip to content

Commit

Permalink
Step 14.28: Tests of rsvp Method
Browse files Browse the repository at this point in the history
  • Loading branch information
Kamil Kisiela authored and Dotan Simha committed Nov 22, 2016
1 parent 093cf14 commit b01fd45
Showing 1 changed file with 53 additions and 1 deletion.
54 changes: 53 additions & 1 deletion imports/api/parties/methods.tests.js
@@ -1,4 +1,4 @@
import { invite } from './methods';
import { invite, rsvp } from './methods';
import { Parties } from './collection';

import { Meteor } from 'meteor/meteor';
Expand Down Expand Up @@ -122,5 +122,57 @@ if (Meteor.isServer) {
});
});
});

describe('rsvp', () => {
function loggedIn(userId = 'userId') {
return {
userId
};
}

it('should be called from Method', () => {
spyOn(rsvp, 'apply');

try {
Meteor.call('rsvp');
} catch (e) {}

expect(rsvp.apply).toHaveBeenCalled();
});

it('should fail on missing partyId', () => {
expect(() => {
rsvp.call({});
}).toThrowError();
});

it('should fail on missing rsvp', () => {
expect(() => {
rsvp.call({}, 'partyId');
}).toThrowError();
});

it('should fail if not logged in', () => {
expect(() => {
rsvp.call({}, 'partyId', 'rsvp');
}).toThrowError(/403/);
});

it('should fail on wrong answer', () => {
expect(() => {
rsvp.call(loggedIn(), 'partyId', 'wrong');
}).toThrowError(/400/);
});

['yes', 'maybe', 'no'].forEach((answer) => {
it(`should pass on '${answer}'`, () => {
expect(() => {
rsvp.call(loggedIn(), 'partyId', answer);
}).not.toThrowError(/400/);
});
});

// TODO: more tests
});
});
}

0 comments on commit b01fd45

Please sign in to comment.