Skip to content

Commit

Permalink
Adding factory tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mkdbns committed Jul 8, 2017
1 parent 044b9f6 commit 4fb38d5
Show file tree
Hide file tree
Showing 4 changed files with 90 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/factory/directChannel.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const validate = require('./validate')
//
const schema = {
header: Joi.string().allow('').optional(),
members: Joi.array().items(Joi.string())
members: Joi.array().items(Joi.string()).min(2)
}

//
Expand Down
2 changes: 1 addition & 1 deletion lib/factory/directPost.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const validate = require('./validate')
// Define the schema
//
const schema = {
channel_members: Joi.array().items(Joi.string()),
channel_members: Joi.array().items(Joi.string()).min(2),
user: Joi.string(),
message: Joi.string(),
create_at: Joi.number()
Expand Down
35 changes: 35 additions & 0 deletions lib/factory/test/directChannel.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
const expect = require('chai').expect
const directChannel = require('../directChannel')

const basic = {
members:[
'username1',
'username2'
]
}

describe('team factory', function() {

it('should produce a valid object', function() {
var c = directChannel(basic)
expect(c).to.be.an('object')
expect(c).to.deep.equal({
type: 'direct_channel',
direct_channel: basic
})
})

it('should prevent less than 2 members', function() {
try {
directChannel(Object.assign({}, basic, {
members:[
'username1'
]
}))
}
catch (e) {
expect(e).to.be.an('error')
expect(e.details[0].message).to.equal('"members" must contain at least 2 items')
}
})
})
53 changes: 53 additions & 0 deletions lib/factory/test/directPost.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
const expect = require('chai').expect
const directPost = require('../directPost')

const basic = {
channel_members: [
'username1',
'username2'
],
user: 'username1',
message: 'carpe diem',
create_at: new Date().getTime()
}

describe('post factory', function() {

it('should produce a valid object', function() {
var p = directPost(basic)
expect(p).to.be.an('object')
expect(p).to.deep.equal({
type: 'direct_post',
direct_post: basic
})
})

it('should ensure message is not empty', function() {
try {
var p = directPost(Object.assign({}, basic, {
message: ''
}))
expect(p).to.be.undefined
}
catch (e) {
expect(e).to.be.an('error')
expect(e.details[0].message).to.equal('"message" is not allowed to be empty')
}
})

it('should prevent less than 2 members', function() {
try {
var p = directPost(Object.assign({}, basic, {
channel_members:[
'username1'
]
}))
expect(p).to.be.undefined
}
catch (e) {
expect(e).to.be.an('error')
expect(e.details[0].message).to.equal('"channel_members" must contain at least 2 items')
}
})

})

0 comments on commit 4fb38d5

Please sign in to comment.