|
| 1 | +/* global expect beforeAll afterAll */ |
| 2 | +import { |
| 3 | + createCommunityEvent, |
| 4 | + getCommunityEvent, |
| 5 | + getCommunityEvents |
| 6 | +} from './communityEvent'; |
| 7 | +import { createUser } from './user'; |
| 8 | +import CommunityEvent from '../model/communityEvent.js'; |
| 9 | +import UserModel from '../model/user.js'; |
| 10 | +import { isObject, isEmpty } from 'lodash'; |
| 11 | +import mongoose from 'mongoose'; |
| 12 | +import { isDate, isArray } from 'util'; |
| 13 | + |
| 14 | +const validContextForBrian = global.mockedContextWithValidTokenForBrian; |
| 15 | +const validContextForDennis = global.mockedContextWithValidTokenForDennis; |
| 16 | +const validContextForKen = global.mockedContextWithValidTokenForKen; |
| 17 | + |
| 18 | +const event = { |
| 19 | + title: 'epoch', |
| 20 | + description: 'The start of POSIX time', |
| 21 | + date: 'Thu 1 Jan 1970 00:00:00' |
| 22 | +}; |
| 23 | + |
| 24 | +const eventValidAttendees = { |
| 25 | + ...event, |
| 26 | + attendees: [ |
| 27 | + |
| 28 | + |
| 29 | + ] |
| 30 | +}; |
| 31 | + |
| 32 | +const eventInValidAttendees = { |
| 33 | + ...event, |
| 34 | + attendees: [{ email: '[email protected]' }] |
| 35 | +}; |
| 36 | + |
| 37 | +beforeAll(async function beforeAllTests() { |
| 38 | + await mongoose.connect(global.__MONGO_URI__); |
| 39 | + |
| 40 | + // Create some users for our tests |
| 41 | + await createUser({}, {}, validContextForBrian); |
| 42 | + await createUser({}, {}, validContextForDennis); |
| 43 | + await createUser({}, {}, validContextForKen); |
| 44 | +}); |
| 45 | + |
| 46 | +afterAll(async function afterAllTests() { |
| 47 | + await mongoose.disconnect(); |
| 48 | +}); |
| 49 | + |
| 50 | +describe('createCommunityEvent', () => { |
| 51 | + it('should return an Event object', done => { |
| 52 | + expect.assertions(2); |
| 53 | + createCommunityEvent({}, eventValidAttendees, validContextForBrian) |
| 54 | + .then(result => { |
| 55 | + const { |
| 56 | + externalId, |
| 57 | + title, |
| 58 | + description, |
| 59 | + owner, |
| 60 | + date, |
| 61 | + attendees |
| 62 | + } = result; |
| 63 | + // there is some weird Promise thing going on with `result` |
| 64 | + // which screws with lodash.has() |
| 65 | + const hasKeys = |
| 66 | + !isEmpty(externalId) && |
| 67 | + !isEmpty(title) && |
| 68 | + !isEmpty(description) && |
| 69 | + !isEmpty(owner) && |
| 70 | + isDate(date) && |
| 71 | + isArray(attendees); |
| 72 | + |
| 73 | + expect(isObject(result)).toBe(true); |
| 74 | + expect(hasKeys).toBe(true); |
| 75 | + return; |
| 76 | + }) |
| 77 | + .then(done) |
| 78 | + .catch(done); |
| 79 | + }); |
| 80 | +}); |
0 commit comments