init
This commit is contained in:
35
lib/factory/test/channel.js
Normal file
35
lib/factory/test/channel.js
Normal file
@@ -0,0 +1,35 @@
|
||||
const expect = require('chai').expect
|
||||
const channel = require('../channel')
|
||||
|
||||
const basic = {
|
||||
team: 'test-team',
|
||||
name: 'test-channel',
|
||||
display_name: 'Test Channel',
|
||||
header: 'Test Channel Header',
|
||||
purpose: 'Test the channel generator',
|
||||
type: 'P'
|
||||
}
|
||||
|
||||
describe('team factory', function() {
|
||||
|
||||
it('should produce a valid object', function() {
|
||||
var c = channel(basic)
|
||||
expect(c).to.be.an('object')
|
||||
expect(c).to.deep.equal({
|
||||
type: 'channel',
|
||||
channel: basic
|
||||
})
|
||||
})
|
||||
|
||||
it('should prevent an invalid type', function() {
|
||||
try {
|
||||
channel(Object.assign({}, basic, {
|
||||
type: 'X'
|
||||
}))
|
||||
}
|
||||
catch (e) {
|
||||
expect(e).to.be.an('error')
|
||||
expect(e.details[0].message).to.equal('"type" must be one of [O, P]')
|
||||
}
|
||||
})
|
||||
})
|
||||
35
lib/factory/test/directChannel.js
Normal file
35
lib/factory/test/directChannel.js
Normal file
@@ -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
lib/factory/test/directPost.js
Normal file
53
lib/factory/test/directPost.js
Normal file
@@ -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')
|
||||
}
|
||||
})
|
||||
|
||||
})
|
||||
35
lib/factory/test/post.js
Normal file
35
lib/factory/test/post.js
Normal file
@@ -0,0 +1,35 @@
|
||||
const expect = require('chai').expect
|
||||
const post = require('../post')
|
||||
|
||||
const basic = {
|
||||
team: 'test',
|
||||
channel: 'channel',
|
||||
user: 'user',
|
||||
message: 'carpe diem',
|
||||
create_at: new Date().getTime()
|
||||
}
|
||||
|
||||
describe('post factory', function() {
|
||||
|
||||
it('should produce a valid object', function() {
|
||||
var p = post(basic)
|
||||
expect(p).to.be.an('object')
|
||||
expect(p).to.deep.equal({
|
||||
type: 'post',
|
||||
post: basic
|
||||
})
|
||||
})
|
||||
|
||||
it('should ensure message is not empty', function() {
|
||||
try {
|
||||
var p = post(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')
|
||||
}
|
||||
})
|
||||
})
|
||||
34
lib/factory/test/team.js
Normal file
34
lib/factory/test/team.js
Normal file
@@ -0,0 +1,34 @@
|
||||
const expect = require('chai').expect
|
||||
const team = require('../team')
|
||||
|
||||
const basic = {
|
||||
name: 'test-team',
|
||||
display_name: 'Test Team',
|
||||
description: 'A test team for testing',
|
||||
type: 'O',
|
||||
allow_open_invite: true
|
||||
}
|
||||
|
||||
describe('team factory', function() {
|
||||
|
||||
it('should produce a valid object', function() {
|
||||
var t = team(basic)
|
||||
expect(t).to.be.an('object')
|
||||
expect(t).to.deep.equal({
|
||||
type: 'team',
|
||||
team: basic
|
||||
})
|
||||
})
|
||||
|
||||
it('should prevent an invalid type', function() {
|
||||
try {
|
||||
team(Object.assign({}, basic, {
|
||||
type: 'X'
|
||||
}))
|
||||
}
|
||||
catch (e) {
|
||||
expect(e).to.be.an('error')
|
||||
expect(e.details[0].message).to.equal('"type" must be one of [O, I]')
|
||||
}
|
||||
})
|
||||
})
|
||||
42
lib/factory/test/user.js
Normal file
42
lib/factory/test/user.js
Normal file
@@ -0,0 +1,42 @@
|
||||
const expect = require('chai').expect
|
||||
const user = require('../user')
|
||||
|
||||
const basic = {
|
||||
username: 'user.name',
|
||||
email: 'user@example.gov',
|
||||
auth_service: 'ldap',
|
||||
auth_data: 'username-field-reference',
|
||||
teams: [{
|
||||
name: 'test',
|
||||
channels: [{
|
||||
name: 'channel-1'
|
||||
}, {
|
||||
name: 'channel-2'
|
||||
}]
|
||||
}]
|
||||
}
|
||||
|
||||
describe('user factory', function() {
|
||||
|
||||
it('should produce a valid object', function() {
|
||||
var u = user(basic)
|
||||
expect(u).to.be.an('object')
|
||||
expect(u).to.deep.equal({
|
||||
type: 'user',
|
||||
user: basic
|
||||
})
|
||||
})
|
||||
|
||||
it('should ensure email is valid', function() {
|
||||
try {
|
||||
var u = user(Object.assign({}, basic, {
|
||||
email: 'foo@bar'
|
||||
}))
|
||||
expect(u).to.be.undefined
|
||||
}
|
||||
catch (e) {
|
||||
expect(e).to.be.an('error')
|
||||
expect(e.details[0].message).to.equal('"email" must be a valid email')
|
||||
}
|
||||
})
|
||||
})
|
||||
13
lib/factory/test/version.js
Normal file
13
lib/factory/test/version.js
Normal file
@@ -0,0 +1,13 @@
|
||||
const expect = require('chai').expect
|
||||
const version = require('../version')
|
||||
|
||||
describe('version factory', function() {
|
||||
it('should produce a valid version', function() {
|
||||
var v = version()
|
||||
expect(v).to.be.an('object')
|
||||
expect(v).to.deep.equal({
|
||||
type: 'version',
|
||||
version: 1
|
||||
})
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user