diff --git a/imports/api/parties/methods.tests.js b/imports/api/parties/methods.tests.js index 56e770cb4..536a2b071 100644 --- a/imports/api/parties/methods.tests.js +++ b/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'; @@ -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 + }); }); }