-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c6d7bee
commit dafb51f
Showing
3 changed files
with
186 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,34 @@ | ||
const mongoose = require('mongoose'); | ||
const Schema = mongoose.Schema; | ||
const Story = require('../model/story.model'); | ||
|
||
const attachmentSchema = new Schema({ | ||
type: String, | ||
url: String, | ||
imageUrl: String, | ||
urlImg: String, | ||
title: String, | ||
text: String, | ||
}); | ||
|
||
const coordinatesSchema = new Schema({ | ||
lat: Number, | ||
lng: Number, | ||
const locationSchema = new Schema({ | ||
lat: String, | ||
lng: String, | ||
}); | ||
|
||
const eventSchema = new Schema({ | ||
title: String, | ||
startTime: String, | ||
dateAndTime: String, | ||
dateAndTime: Date, | ||
mapLocation: String, | ||
coordinates: [coordinatesSchema], | ||
location: locationSchema, | ||
attachments: [attachmentSchema], | ||
}); | ||
|
||
const Event = mongoose.model('Event', eventSchema); | ||
const Coordinates = mongoose.model('Coordinates', coordinatesSchema); | ||
const Location = mongoose.model('Location', locationSchema); | ||
const Attachment = mongoose.model('Attachment', attachmentSchema); | ||
|
||
module.exports = { | ||
Event, | ||
Coordinates, | ||
Location, | ||
Attachment, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,165 @@ | ||
const chai = require('chai'); | ||
var chaiAsPromised = require('chai-as-promised'); | ||
const sinon = require('sinon'); | ||
const sinonChai = require('sinon-chai'); | ||
chai.use(sinonChai); | ||
chai.use(chaiAsPromised); | ||
chai.should(); | ||
require('chai').should(); | ||
const Event = require('../controller/events.controller'); | ||
const proxyquire = require('proxyquire'); | ||
|
||
describe('addEvents', () => { | ||
|
||
it('should not create events if no title is provided', | ||
async () => { | ||
const ctx = { | ||
request: { | ||
body: { | ||
title: '', | ||
startTime: 38, | ||
dateAndTime: 'Thurs 21 December', | ||
mapLocation: 'Barcelona', | ||
attachments: [], | ||
} | ||
} | ||
}; | ||
await Event.addEvent(ctx).should.be.rejected; | ||
} | ||
); | ||
|
||
|
||
it('should search for a story on the DB & save to it', | ||
async () => { | ||
const spy = sinon.spy(); | ||
const EventController = proxyquire('../controller/events.controller', { | ||
'../model/story.model': { | ||
'@noCallThru': true, | ||
findOne: () => ({ | ||
id: 123, | ||
save: spy, | ||
events: [], | ||
}) | ||
} | ||
}); | ||
const ctx = { | ||
params: { | ||
id: 42 | ||
}, | ||
request: { | ||
body: { | ||
title: 'This is a story', | ||
startTime: 38, | ||
dateAndTime: 'Thurs 21 December', | ||
mapLocation: 'Barcelona', | ||
attachments: [], | ||
} | ||
} | ||
}; | ||
await EventController.addEvent(ctx); | ||
spy.calledOnce.should.equal(true); | ||
} | ||
); | ||
|
||
|
||
it('should create an event', | ||
async () => { | ||
const spy = sinon.spy(); | ||
const ctx = { | ||
params: { | ||
id: 42 | ||
}, | ||
request: { | ||
body: { | ||
title: 'This is a story', | ||
startTime: 38, | ||
mapLocation: 'Barcelona', | ||
dateAndTime: 'Thurs 21 December', | ||
attachments: [], | ||
} | ||
} | ||
}; | ||
const mockEvent = { | ||
title: ctx.request.body.title, | ||
startTime: ctx.request.body.startTime, | ||
mapLocation: ctx.request.body.mapLocation, | ||
dateAndTime: ctx.request.body.dateAndTime, | ||
attachments: ctx.request.body.attachments | ||
}; | ||
const EventController = proxyquire('../controller/events.controller', | ||
|
||
{ | ||
'../model/story.model': { | ||
'@noCallThru': true, | ||
findOne: () => ({ | ||
id: 123, | ||
save: spy, | ||
events: [], | ||
}) | ||
} | ||
}, | ||
|
||
{ | ||
'../model/event.model': { | ||
'@noCallThru': true, | ||
create: () => mockEvent | ||
} | ||
}); | ||
|
||
await EventController.addEvent(ctx); | ||
ctx.request.body.should.eql(mockEvent); | ||
} | ||
); | ||
|
||
|
||
it('should be called with the provided arguments', | ||
function () { | ||
var addEventSpy = sinon.spy(Event.addEvent); | ||
Event.addEvent(true, true); | ||
addEventSpy.calledWith(true, true); | ||
// addEventSpy.restore(); | ||
} | ||
); | ||
|
||
|
||
|
||
it('should update events when edited', async () => { | ||
|
||
}); | ||
|
||
|
||
|
||
|
||
it('should have unique startTime'); | ||
|
||
it('should update attachments'); | ||
|
||
}); | ||
|
||
|
||
|
||
describe('Edit Event', function () { | ||
|
||
|
||
}); | ||
|
||
describe('Delete Event', function () { | ||
|
||
it('should remove event from DB when deleted', async () => { | ||
|
||
|
||
|
||
|
||
}); | ||
|
||
}); | ||
|
||
|
||
describe('Attachments', () => { | ||
it('should validate text format'); | ||
it('should validate tweet format'); | ||
it('should validate image format'); | ||
it('should validate video format'); | ||
it('should validate audio format'); | ||
it('should validate link format'); | ||
}); |