-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' of https://github.com/ufabc-next/ufabc-next-server
- Loading branch information
Showing
6 changed files
with
127 additions
and
126 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,68 +1,68 @@ | ||
const app = require('@/app') | ||
const func = require('./func') | ||
const assert = require('assert') | ||
const populate = require('@/populate') | ||
// const app = require('@/app') | ||
// const func = require('./func') | ||
// const assert = require('assert') | ||
// const populate = require('@/populate') | ||
|
||
describe('POST /v1/comments', async function () { | ||
let models | ||
let context | ||
let enrollment | ||
beforeEach(async function () { | ||
models = await populate({ | ||
operation: 'both', | ||
only: ['enrollments', 'teachers', 'subjects', 'comments'], | ||
}) | ||
// describe('POST /v1/comments', async function () { | ||
// let models | ||
// let context | ||
// let enrollment | ||
// beforeEach(async function () { | ||
// models = await populate({ | ||
// operation: 'both', | ||
// only: ['enrollments', 'teachers', 'subjects', 'comments'], | ||
// }) | ||
|
||
enrollment = models.enrollments[0] | ||
context = { | ||
body: { | ||
enrollment: enrollment._id, | ||
comment: 'Some comment', | ||
type: 'pratica', | ||
}, | ||
} | ||
}) | ||
describe('func', async function () { | ||
describe('with valid params', async function () { | ||
it('create and return a filtered comment', async function () { | ||
const resp = await func(context) | ||
// enrollment = models.enrollments[0] | ||
// context = { | ||
// body: { | ||
// enrollment: enrollment._id, | ||
// comment: 'Some comment', | ||
// type: 'pratica', | ||
// }, | ||
// } | ||
// }) | ||
// describe('func', async function () { | ||
// describe('with valid params', async function () { | ||
// it('create and return a filtered comment', async function () { | ||
// const resp = await func(context) | ||
|
||
assert(resp._id) | ||
assert.equal(resp.comment, context.body.comment) | ||
assert(resp.createdAt) | ||
assert(new Date() > resp.createdAt) | ||
assert.equal(resp.enrollment._id, context.body.enrollment) | ||
assert.equal(resp.subject, enrollment.subject) | ||
assert.equal(resp.teacher, enrollment.mainTeacher) | ||
assert.notEqual(resp.ra, enrollment.ra) | ||
// assert(resp._id) | ||
// assert.equal(resp.comment, context.body.comment) | ||
// assert(resp.createdAt) | ||
// assert(new Date() > resp.createdAt) | ||
// assert.equal(resp.enrollment._id, context.body.enrollment) | ||
// assert.equal(resp.subject, enrollment.subject) | ||
// assert.equal(resp.teacher, enrollment.mainTeacher) | ||
// assert.notEqual(resp.ra, enrollment.ra) | ||
|
||
const Comment = app.models.comments | ||
const comment = await Comment.findOne({ _id: resp._id }) | ||
assert(comment) | ||
}) | ||
}) | ||
describe('with invalid params', async function () { | ||
it('should throw if enrollment is missing', async function () { | ||
delete context.body.enrollment | ||
await assertFuncThrows('MissingParameter', func, context) | ||
}) | ||
it('should throw if comment is missing', async function () { | ||
delete context.body.comment | ||
await assertFuncThrows('MissingParameter', func, context) | ||
}) | ||
it('should throw if type is missing', async function () { | ||
delete context.body.type | ||
await assertFuncThrows('MissingParameter', func, context) | ||
}) | ||
it('should throw if enrollment is invalid', async function () { | ||
// Invalid enrollment id | ||
context.body.enrollment = models.comments[0]._id | ||
await assertFuncThrows('BadRequest', func, context) | ||
}) | ||
it('should throw if is a duplicated comment', async function () { | ||
await func(context) | ||
await assertFuncThrows('BadRequest', func, context) | ||
}) | ||
}) | ||
}) | ||
}) | ||
// const Comment = app.models.comments | ||
// const comment = await Comment.findOne({ _id: resp._id }) | ||
// assert(comment) | ||
// }) | ||
// }) | ||
// describe('with invalid params', async function () { | ||
// it('should throw if enrollment is missing', async function () { | ||
// delete context.body.enrollment | ||
// await assertFuncThrows('MissingParameter', func, context) | ||
// }) | ||
// it('should throw if comment is missing', async function () { | ||
// delete context.body.comment | ||
// await assertFuncThrows('MissingParameter', func, context) | ||
// }) | ||
// it('should throw if type is missing', async function () { | ||
// delete context.body.type | ||
// await assertFuncThrows('MissingParameter', func, context) | ||
// }) | ||
// it('should throw if enrollment is invalid', async function () { | ||
// // Invalid enrollment id | ||
// context.body.enrollment = models.comments[0]._id | ||
// await assertFuncThrows('BadRequest', func, context) | ||
// }) | ||
// it('should throw if is a duplicated comment', async function () { | ||
// await func(context) | ||
// await assertFuncThrows('BadRequest', func, context) | ||
// }) | ||
// }) | ||
// }) | ||
// }) |
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,55 +1,55 @@ | ||
const app = require('@/app') | ||
const Axios = require('axios') | ||
const sinon = require('sinon') | ||
const assert = require('assert') | ||
const populate = require('@/populate') | ||
|
||
const send = require('./send') | ||
|
||
describe('HELPER mailer/send', async function(){ | ||
let stub | ||
|
||
beforeEach(async function () { | ||
await populate({ operation: 'both' }) | ||
stub = sinon.stub(Axios, 'post') | ||
}) | ||
|
||
afterEach(async function () { | ||
stub.restore() | ||
}) | ||
|
||
it('send a email to a single recipient', async function(){ | ||
const email = { | ||
recipient: 'email@test.com', | ||
body: { | ||
name: 'My name' | ||
} | ||
} | ||
|
||
const sender = { name: 'test', email: 'sender@email.com' } | ||
|
||
await send(email, sender, 'templateId') | ||
assert.equal(stub.callCount, 1) | ||
assert.equal(stub.firstCall.args[0], 'https://api.sendgrid.com/v3/mail/send') | ||
const params = stub.firstCall.args[1] | ||
assert.equal(params.personalizations.length, 1) | ||
assert.equal(params.from.name, sender.name) | ||
assert.equal(params.from.email, app.config.mailer.EMAIL) | ||
assert.equal(params.reply_to.email, sender.email) | ||
}) | ||
|
||
it('send a email for multiple single recipient', async function(){ | ||
const email = [{ | ||
recipient: 'email@test.com', | ||
body: { name: 'My name' } | ||
}, { | ||
recipient: 'email2@test.com' | ||
}] | ||
|
||
await send(email, {}, 'templateId') | ||
assert.equal(stub.callCount, 1) | ||
assert.equal(stub.firstCall.args[0], 'https://api.sendgrid.com/v3/mail/send') | ||
const params = stub.firstCall.args[1] | ||
assert.equal(params.personalizations.length, 2) | ||
}) | ||
}) | ||
// const app = require('@/app') | ||
// const Axios = require('axios') | ||
// const sinon = require('sinon') | ||
// const assert = require('assert') | ||
// const populate = require('@/populate') | ||
|
||
// const send = require('./send') | ||
|
||
// describe('HELPER mailer/send', async function(){ | ||
// let stub | ||
|
||
// beforeEach(async function () { | ||
// await populate({ operation: 'both' }) | ||
// stub = sinon.stub(Axios, 'post') | ||
// }) | ||
|
||
// afterEach(async function () { | ||
// stub.restore() | ||
// }) | ||
|
||
// it('send a email to a single recipient', async function(){ | ||
// const email = { | ||
// recipient: 'email@test.com', | ||
// body: { | ||
// name: 'My name' | ||
// } | ||
// } | ||
|
||
// const sender = { name: 'test', email: 'sender@email.com' } | ||
|
||
// await send(email, sender, 'templateId') | ||
// assert.equal(stub.callCount, 1) | ||
// assert.equal(stub.firstCall.args[0], 'https://api.sendgrid.com/v3/mail/send') | ||
// const params = stub.firstCall.args[1] | ||
// assert.equal(params.personalizations.length, 1) | ||
// assert.equal(params.from.name, sender.name) | ||
// assert.equal(params.from.email, app.config.mailer.EMAIL) | ||
// assert.equal(params.reply_to.email, sender.email) | ||
// }) | ||
|
||
// it('send a email for multiple single recipient', async function(){ | ||
// const email = [{ | ||
// recipient: 'email@test.com', | ||
// body: { name: 'My name' } | ||
// }, { | ||
// recipient: 'email2@test.com' | ||
// }] | ||
|
||
// await send(email, {}, 'templateId') | ||
// assert.equal(stub.callCount, 1) | ||
// assert.equal(stub.firstCall.args[0], 'https://api.sendgrid.com/v3/mail/send') | ||
// const params = stub.firstCall.args[1] | ||
// assert.equal(params.personalizations.length, 2) | ||
// }) | ||
// }) |
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