init
This commit is contained in:
61
lib/modules/test/channels.js
Normal file
61
lib/modules/test/channels.js
Normal file
@@ -0,0 +1,61 @@
|
||||
const expect = require('chai').expect
|
||||
const channels = require('../channels')
|
||||
const Fixtures = require('./fixtures')
|
||||
const context = require('./context')()
|
||||
|
||||
describe('modules.channels', function() {
|
||||
|
||||
it('should process channel objects', function(done) {
|
||||
|
||||
context.values.team = context.config.define.team
|
||||
|
||||
context.jabber.fetch.returns(Promise.resolve({
|
||||
recordset: Fixtures.channels
|
||||
}))
|
||||
|
||||
channels(context)
|
||||
.then(function (c) {
|
||||
expect(c).to.equal(context)
|
||||
expect(Object.keys(c.values.channels).length).equals(3)
|
||||
expect(c.output.write.args[0][0]).to.deep.equal({
|
||||
type: 'channel',
|
||||
channel: {
|
||||
team: 'test',
|
||||
name: 'admin',
|
||||
display_name: 'Admin',
|
||||
header: 'Admin Room',
|
||||
purpose: 'Admin Room',
|
||||
type: 'O'
|
||||
}
|
||||
})
|
||||
expect(c.output.write.args[1][0]).to.deep.equal({
|
||||
type: 'channel',
|
||||
channel: {
|
||||
team: 'test',
|
||||
name: 'test-room',
|
||||
display_name: 'Test Room',
|
||||
header: '',
|
||||
purpose: '',
|
||||
type: 'O'
|
||||
}
|
||||
})
|
||||
expect(c.output.write.args[2][0]).to.deep.equal({
|
||||
type: 'channel',
|
||||
channel: {
|
||||
team: 'test',
|
||||
name: 'tonyd_20161206_1432',
|
||||
display_name: 'Tonyd 20161206 1432',
|
||||
header: '',
|
||||
purpose: '',
|
||||
type: 'O'
|
||||
}
|
||||
})
|
||||
done()
|
||||
})
|
||||
})
|
||||
|
||||
afterEach(function() {
|
||||
context.jabber.fetch.reset()
|
||||
context.output.write.reset()
|
||||
})
|
||||
})
|
||||
38
lib/modules/test/context.js
Normal file
38
lib/modules/test/context.js
Normal file
@@ -0,0 +1,38 @@
|
||||
const { spy, stub } = require('sinon')
|
||||
|
||||
module.exports = function() {
|
||||
return {
|
||||
config: {
|
||||
source: {
|
||||
uri: 'mssql://username:password@server:1433/jabber?encrypt=true'
|
||||
},
|
||||
target: {
|
||||
filename: 'data.json'
|
||||
},
|
||||
define: {
|
||||
team: {
|
||||
name: 'test',
|
||||
display_name: 'Test Team',
|
||||
description: 'Our Test Team',
|
||||
type: 'I',
|
||||
allow_open_invite: false
|
||||
},
|
||||
user: {
|
||||
auth_service: 'ldap',
|
||||
}
|
||||
}
|
||||
},
|
||||
jabber: {
|
||||
connect: stub().returns(Promise.resolve()),
|
||||
fetch: stub(),
|
||||
pipe: stub()
|
||||
},
|
||||
values: {
|
||||
|
||||
},
|
||||
output: {
|
||||
write: spy(),
|
||||
end: spy()
|
||||
}
|
||||
}
|
||||
}
|
||||
70
lib/modules/test/directChannels.js
Normal file
70
lib/modules/test/directChannels.js
Normal file
@@ -0,0 +1,70 @@
|
||||
const expect = require('chai').expect
|
||||
const directChannels = require('../directChannels')
|
||||
const Fixtures = require('./fixtures')
|
||||
const FakeDB = require('./fakedb')
|
||||
const sink = require('./sink')
|
||||
const context = require('./context')()
|
||||
|
||||
describe('modules.directChannels', function() {
|
||||
|
||||
before(function() {
|
||||
//
|
||||
// Set up context values
|
||||
//
|
||||
context.values = {
|
||||
users: {
|
||||
'person.one@example.com': {
|
||||
username: 'person.one'
|
||||
},
|
||||
'person.two@example.com': {
|
||||
username: 'person.two'
|
||||
},
|
||||
'person.three@example.com': {
|
||||
username: 'person.three'
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
beforeEach(function() {
|
||||
//
|
||||
// Stub the output stream
|
||||
//
|
||||
context.output = sink()
|
||||
})
|
||||
|
||||
it('should process direct channel objects', function(done) {
|
||||
//
|
||||
// Set up the DB
|
||||
//
|
||||
context.jabber = new FakeDB(Fixtures.directChannels)
|
||||
//
|
||||
// Process the data
|
||||
//
|
||||
directChannels(context).then(function(c) {
|
||||
expect(c).to.equal(context)
|
||||
expect(c.output.write.args).to.deep.equal(
|
||||
[
|
||||
[
|
||||
{
|
||||
type: 'direct_channel',
|
||||
direct_channel: {
|
||||
members: ['person.one', 'person.two']
|
||||
}
|
||||
}
|
||||
],
|
||||
[
|
||||
{
|
||||
type: 'direct_channel',
|
||||
direct_channel: {
|
||||
members: ['person.one', 'person.three']
|
||||
}
|
||||
}
|
||||
]
|
||||
]
|
||||
)
|
||||
|
||||
done()
|
||||
})
|
||||
})
|
||||
})
|
||||
91
lib/modules/test/directPosts.js
Normal file
91
lib/modules/test/directPosts.js
Normal file
@@ -0,0 +1,91 @@
|
||||
const expect = require('chai').expect
|
||||
const directPosts = require('../directPosts')
|
||||
const Fixtures = require('./fixtures')
|
||||
const FakeDB = require('./fakedb')
|
||||
const sink = require('./sink')
|
||||
const context = require('./context')()
|
||||
|
||||
describe('modules.directPosts', function() {
|
||||
|
||||
before(function() {
|
||||
//
|
||||
// Set up context values
|
||||
//
|
||||
context.values = {
|
||||
users: {
|
||||
'person.one@example.com': {
|
||||
username: 'person.one'
|
||||
},
|
||||
'person.two@example.com': {
|
||||
username: 'person.two'
|
||||
},
|
||||
'person.three@example.com': {
|
||||
username: 'person.three'
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
beforeEach(function() {
|
||||
//
|
||||
// Stub the output stream
|
||||
//
|
||||
context.output = sink()
|
||||
})
|
||||
|
||||
it('should process direct channel objects', function(done) {
|
||||
//
|
||||
// Set up the DB
|
||||
//
|
||||
context.jabber = new FakeDB(Fixtures.directPosts)
|
||||
//
|
||||
// Process the data
|
||||
//
|
||||
directPosts(context).then(function(c) {
|
||||
expect(c).to.equal(context)
|
||||
expect(c.output.write.args).to.deep.equal([
|
||||
[
|
||||
{
|
||||
type: 'direct_post',
|
||||
direct_post: {
|
||||
channel_members: [
|
||||
'person.one', 'person.two'
|
||||
],
|
||||
user: 'person.two',
|
||||
message: 'message 01',
|
||||
create_at: 1497066628513
|
||||
}
|
||||
}
|
||||
],
|
||||
[
|
||||
{
|
||||
type: 'direct_post',
|
||||
direct_post: {
|
||||
channel_members: [
|
||||
'person.one', 'person.three'
|
||||
],
|
||||
user: 'person.three',
|
||||
message: 'message 02',
|
||||
create_at: 1497066628514
|
||||
}
|
||||
}
|
||||
],
|
||||
[
|
||||
{
|
||||
type: 'direct_post',
|
||||
direct_post: {
|
||||
channel_members: [
|
||||
'person.one', 'person.two'
|
||||
],
|
||||
user: 'person.one',
|
||||
message: 'message 03',
|
||||
create_at: 1497066628515
|
||||
}
|
||||
}
|
||||
]
|
||||
])
|
||||
|
||||
done()
|
||||
})
|
||||
})
|
||||
})
|
||||
14
lib/modules/test/end.js
Normal file
14
lib/modules/test/end.js
Normal file
@@ -0,0 +1,14 @@
|
||||
const expect = require('chai').expect
|
||||
const end = require('../end')
|
||||
const context = require('./context')()
|
||||
|
||||
describe('modules.end', function() {
|
||||
it('should close the output stream', function() {
|
||||
end(context)
|
||||
expect(context.output.end.called).to.be.true
|
||||
})
|
||||
|
||||
afterEach(function() {
|
||||
context.output.end.reset()
|
||||
})
|
||||
})
|
||||
50
lib/modules/test/fakedb.js
Normal file
50
lib/modules/test/fakedb.js
Normal file
@@ -0,0 +1,50 @@
|
||||
//
|
||||
// Implements a fake db for testing
|
||||
//
|
||||
class FakeDB {
|
||||
//
|
||||
// Constructor
|
||||
//
|
||||
constructor(data) {
|
||||
this.data = data
|
||||
this.fetch = this.fetch.bind(this)
|
||||
this.pipe = this.pipe.bind(this)
|
||||
}
|
||||
|
||||
//
|
||||
// Simulate a db connection by just returning
|
||||
// a promise
|
||||
//
|
||||
connect() {
|
||||
return Promise.resolve()
|
||||
}
|
||||
|
||||
//
|
||||
// Returns all results in one batch
|
||||
//
|
||||
fetch() {
|
||||
return Promise.resolve({
|
||||
recordset: this.data
|
||||
})
|
||||
}
|
||||
|
||||
//
|
||||
// Delivers results to the specified write
|
||||
// stream
|
||||
//
|
||||
pipe(query, writable) {
|
||||
|
||||
this.data.forEach(function(record) {
|
||||
writable.write(record)
|
||||
})
|
||||
|
||||
writable.end()
|
||||
|
||||
return writable
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Export the class
|
||||
//
|
||||
module.exports = FakeDB
|
||||
15
lib/modules/test/fixtures/channels.js
vendored
Normal file
15
lib/modules/test/fixtures/channels.js
vendored
Normal file
@@ -0,0 +1,15 @@
|
||||
module.exports = [
|
||||
{
|
||||
room_jid: 'admin@room.example.com',
|
||||
subject: 'Admin Room',
|
||||
config: '<x type=\'submit\' xmlns=\'jabber:x:data\'><field type=\'boolean\' var=\'persistent\'><value>1</value></field><field type=\'text-single\' var=\'max-persistent-history\'><value>15</value></field><field type=\'boolean\' var=\'open-membership\'><value>1</value></field><field type=\'boolean\' var=\'members-only\'><value>0</value></field><field type=\'boolean\' var=\'allow-gc\'><value>1</value></field><field type=\'boolean\' var=\'anonymous\'><value>1</value></field><field type=\'boolean\' var=\'show-unavailable\'><value>1</value></field><field type=\'list-single\' var=\'invite-role\'><value>participant</value></field><field type=\'boolean\' var=\'password\'><value>0</value></field><field type=\'text-private\' var=\'secret\'><value/></field><field type=\'list-single\' var=\'subject-acl\'><value>moderator</value></field><field type=\'boolean\' var=\'strip-xhtml\'><value>0</value></field><field type=\'boolean\' var=\'moderated-room\'><value>0</value></field></x>',
|
||||
}, {
|
||||
room_jid: 'test\\20room@room.example.com',
|
||||
subject: '',
|
||||
config: '<x type=\'submit\' xmlns=\'jabber:x:data\'><field type=\'boolean\' var=\'persistent\'><value>1</value></field><field type=\'text-single\' var=\'max-persistent-history\'><value>15</value></field><field type=\'boolean\' var=\'open-membership\'><value>1</value></field><field type=\'boolean\' var=\'members-only\'><value>0</value></field><field type=\'boolean\' var=\'allow-gc\'><value>1</value></field><field type=\'boolean\' var=\'anonymous\'><value>0</value></field><field type=\'boolean\' var=\'show-unavailable\'><value>1</value></field><field type=\'list-single\' var=\'invite-role\'><value>participant</value></field><field type=\'boolean\' var=\'password\'><value>0</value></field><field type=\'text-private\' var=\'secret\'><value/></field><field type=\'list-single\' var=\'subject-acl\'><value>moderator</value></field><field type=\'boolean\' var=\'strip-xhtml\'><value>0</value></field><field type=\'boolean\' var=\'moderated-room\'><value>0</value></field></x>',
|
||||
}, {
|
||||
room_jid: 'tonyd_20161206_1432@room.example.com',
|
||||
subject: '',
|
||||
config: '<x type=\'submit\' xmlns=\'jabber:x:data\'><field type=\'boolean\' var=\'persistent\'><value>1</value></field><field type=\'text-single\' var=\'max-persistent-history\'><value>15</value></field><field type=\'boolean\' var=\'open-membership\'><value>1</value></field><field type=\'boolean\' var=\'members-only\'><value>0</value></field><field type=\'boolean\' var=\'allow-gc\'><value>1</value></field><field type=\'boolean\' var=\'anonymous\'><value>0</value></field><field type=\'boolean\' var=\'show-unavailable\'><value>1</value></field><field type=\'list-single\' var=\'invite-role\'><value>participant</value></field><field type=\'boolean\' var=\'password\'><value>0</value></field><field type=\'text-private\' var=\'secret\'><value/></field><field type=\'list-single\' var=\'subject-acl\'><value>moderator</value></field><field type=\'boolean\' var=\'strip-xhtml\'><value>0</value></field><field type=\'boolean\' var=\'moderated-room\'><value>0</value></field></x>',
|
||||
}
|
||||
]
|
||||
15
lib/modules/test/fixtures/directChannels.js
vendored
Normal file
15
lib/modules/test/fixtures/directChannels.js
vendored
Normal file
@@ -0,0 +1,15 @@
|
||||
module.exports = [
|
||||
{
|
||||
to_jid: 'person.one@example.com/rnq1gmague',
|
||||
from_jid: 'person.two@example.com/objc04v73q'
|
||||
}, {
|
||||
to_jid: 'person.one@example.com/rnq1gmague',
|
||||
from_jid: 'person.three@example.com/w32ugtn6ch'
|
||||
}, {
|
||||
to_jid: 'person.two@example.com',
|
||||
from_jid: 'person.one@example.com/blrjlefa3a'
|
||||
}, {
|
||||
to_jid: 'person.two@example.com/lhdms8czsw',
|
||||
from_jid: 'person.one@example.com/blrjlefa3a'
|
||||
}
|
||||
]
|
||||
27
lib/modules/test/fixtures/directPosts.js
vendored
Normal file
27
lib/modules/test/fixtures/directPosts.js
vendored
Normal file
@@ -0,0 +1,27 @@
|
||||
module.exports = [
|
||||
{
|
||||
to_jid: 'person.one@example.com/Jabber Messenger Desktop',
|
||||
from_jid: 'person.two@example.com/g1b9b8hs09',
|
||||
sent_date: '2017-06-10T03:50:28.513Z',
|
||||
body_string: 'message 01',
|
||||
body_text: ''
|
||||
}, {
|
||||
to_jid: 'person.one@example.com/Jabber Messenger Desktop',
|
||||
from_jid: 'person.three@example.com/g1b9b8hs09',
|
||||
sent_date: '2017-06-10T03:50:28.514Z',
|
||||
body_string: 'message 02',
|
||||
body_text: ''
|
||||
}, {
|
||||
to_jid: 'person.two@example.com/g1b9b8hs09',
|
||||
from_jid: 'person.one@example.com/Jabber Messenger Desktop',
|
||||
sent_date: '2017-06-10T03:50:28.515Z',
|
||||
body_string: '',
|
||||
body_text: 'message 03'
|
||||
}, {
|
||||
to_jid: 'person.two@example.com/g1b9b8hs09',
|
||||
from_jid: 'person.two@example.com/g1b9b8hs08',
|
||||
sent_date: '2017-06-10T03:50:28.515Z',
|
||||
body_string: 'This should not be exported',
|
||||
body_text: ''
|
||||
}
|
||||
]
|
||||
13
lib/modules/test/fixtures/index.js
vendored
Normal file
13
lib/modules/test/fixtures/index.js
vendored
Normal file
@@ -0,0 +1,13 @@
|
||||
const channels = require('./channels')
|
||||
const users = require('./users')
|
||||
const posts = require('./posts')
|
||||
const directChannels = require('./directChannels')
|
||||
const directPosts = require('./directPosts')
|
||||
|
||||
module.exports = {
|
||||
channels,
|
||||
users,
|
||||
posts,
|
||||
directChannels,
|
||||
directPosts
|
||||
}
|
||||
43
lib/modules/test/fixtures/posts.js
vendored
Normal file
43
lib/modules/test/fixtures/posts.js
vendored
Normal file
@@ -0,0 +1,43 @@
|
||||
module.exports = {
|
||||
|
||||
ok: [{
|
||||
msg_id: '3315',
|
||||
to_jid: 'uat-appsupport@conference.example.com',
|
||||
from_jid: 'micahel.cross@example.com',
|
||||
sent_date: '2017-06-05T20:08:38.263Z',
|
||||
body_string: 'I meant thick',
|
||||
body_text: ''
|
||||
}, {
|
||||
msg_id: '3334',
|
||||
to_jid: 'uat-appsupport@conference.example.com',
|
||||
from_jid: 'micahel.cross@example.com',
|
||||
sent_date: '2017-06-05T20:08:38.263Z',
|
||||
body_string: 'that is when I came on again',
|
||||
body_text: ''
|
||||
}],
|
||||
|
||||
userNotFound: [{
|
||||
msg_id: '3334',
|
||||
to_jid: 'uat-appsupport@conference.example.com',
|
||||
from_jid: 'terrence.flynn@example.com',
|
||||
sent_date: '2017-06-05T20:08:38.263Z',
|
||||
body_string: 'that is when I came on again',
|
||||
body_text: ''
|
||||
}, {
|
||||
msg_id: '3315',
|
||||
to_jid: 'uat-appsupport@conference.example.com',
|
||||
from_jid: 'micahel.cross@example.com',
|
||||
sent_date: '2017-06-05T20:08:38.263Z',
|
||||
body_string: 'I meant thick',
|
||||
body_text: ''
|
||||
}],
|
||||
|
||||
bodyNotFound: [{
|
||||
msg_id: '3315',
|
||||
to_jid: 'uat-appsupport@conference.example.com',
|
||||
from_jid: 'micahel.cross@example.com',
|
||||
sent_date: '2017-06-05T20:08:38.263Z',
|
||||
body_string: '',
|
||||
body_text: ''
|
||||
}]
|
||||
}
|
||||
57
lib/modules/test/fixtures/users.js
vendored
Normal file
57
lib/modules/test/fixtures/users.js
vendored
Normal file
@@ -0,0 +1,57 @@
|
||||
module.exports = [
|
||||
{
|
||||
room_jid: 'admin@conference.example.com',
|
||||
real_jid: 'micahel.cross@example.com'
|
||||
}, {
|
||||
room_jid: 'admin@conference.example.com',
|
||||
real_jid: 'sbarclay@example.com'
|
||||
}, {
|
||||
room_jid: 'uat-appsupport@conference.example.com',
|
||||
real_jid: 'anthony.brown@example.com'
|
||||
}, {
|
||||
room_jid: 'uat-appsupport@conference.example.com',
|
||||
real_jid: 'james.seegar1@example.com'
|
||||
}, {
|
||||
room_jid: 'uat-appsupport@conference.example.com',
|
||||
real_jid: 'jarrett.jennings2@example.com'
|
||||
}, {
|
||||
room_jid: 'uat-appsupport@conference.example.com',
|
||||
real_jid: 'micahel.cross@example.com'
|
||||
}, {
|
||||
room_jid: 'uat-appsupport@conference.example.com',
|
||||
real_jid: 'michael.rhoades3@example.com'
|
||||
}, {
|
||||
room_jid: 'uat-appsupport@conference.example.com',
|
||||
real_jid: 'michael.rock@example.com'
|
||||
}, {
|
||||
room_jid: 'uat-appsupport@conference.example.com',
|
||||
real_jid: 'terrence.flynn@example.com'
|
||||
}, {
|
||||
room_jid: 'uat-appsupport@conference.example.com',
|
||||
real_jid: 'tony.dilisio2@example.com'
|
||||
}, {
|
||||
room_jid: 'uat-appsupport@conference.example.com',
|
||||
real_jid: 'william.fleming2@example.com'
|
||||
}, {
|
||||
room_jid: 'test\\20room@conference.example.com',
|
||||
real_jid: 'lt.u755@example.com'
|
||||
}, {
|
||||
room_jid: 'test\\20room@conference.example.com',
|
||||
real_jid: 'lt.u755@example.com/9fyg1zayoi'
|
||||
}, {
|
||||
room_jid: 'the\\20cool\\20room@conference.example.com',
|
||||
real_jid: 'cody.webb@example.com'
|
||||
}, {
|
||||
room_jid: 'tonyd_20161206_1432@conference.example.com',
|
||||
real_jid: 'tony.dilisio2@example.com'
|
||||
}, {
|
||||
room_jid: 'tonyd_20161206_1432@conference.example.com',
|
||||
real_jid: 'julie..sokol@example.com'
|
||||
}, {
|
||||
real_jid: 'mbcross',
|
||||
room_jid: null
|
||||
},{
|
||||
real_jid: 'cross,\\20michael@chat.dhs.gov',
|
||||
room_jid: null
|
||||
}
|
||||
]
|
||||
131
lib/modules/test/posts.js
Normal file
131
lib/modules/test/posts.js
Normal file
@@ -0,0 +1,131 @@
|
||||
const expect = require('chai').expect
|
||||
const posts = require('../posts')
|
||||
const Fixtures = require('./fixtures')
|
||||
const FakeDB = require('./fakedb')
|
||||
const sink = require('./sink')
|
||||
const context = require('./context')()
|
||||
|
||||
describe('modules.posts', function() {
|
||||
|
||||
before(function() {
|
||||
//
|
||||
// Set up context values
|
||||
//
|
||||
context.values = {
|
||||
team: context.config.define.team,
|
||||
channels: {
|
||||
'uat-appsupport@conference.example.com': {
|
||||
team: 'test',
|
||||
name: 'uat-appsupport',
|
||||
display_name: 'Uat Appsupport',
|
||||
header: '',
|
||||
purpose: '',
|
||||
type: 'P'
|
||||
}
|
||||
},
|
||||
users: {
|
||||
'micahel.cross@example.com': {
|
||||
username: 'micahel.cross',
|
||||
email: 'micahel.cross@example.com',
|
||||
auth_service: 'ldap',
|
||||
teams: [
|
||||
{
|
||||
name: 'test',
|
||||
channels: [
|
||||
{
|
||||
name: 'uat-appsupport'
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
beforeEach(function() {
|
||||
//
|
||||
// Stub the output stream
|
||||
//
|
||||
context.output = sink()
|
||||
})
|
||||
|
||||
it('should process post objects', function(done) {
|
||||
//
|
||||
// Set up the DB
|
||||
//
|
||||
context.jabber = new FakeDB(Fixtures.posts.ok)
|
||||
//
|
||||
// Process the posts
|
||||
//
|
||||
posts(context).then(function(c) {
|
||||
expect(c).to.equal(context)
|
||||
expect(context.output.write.callCount).to.equal(2)
|
||||
|
||||
let post = c.output.write.args[0][0]
|
||||
expect(post).to.deep.equal({
|
||||
type: 'post',
|
||||
post: {
|
||||
team: 'test',
|
||||
channel: 'uat-appsupport',
|
||||
user: 'micahel.cross',
|
||||
message: 'I meant thick',
|
||||
create_at: 1496693318263
|
||||
}
|
||||
})
|
||||
expect(new Date(post.post.create_at).toISOString()).to.equal('2017-06-05T20:08:38.263Z')
|
||||
done()
|
||||
}).catch(function(e){
|
||||
expect(e).to.be.undefined
|
||||
})
|
||||
})
|
||||
|
||||
|
||||
it('should fail on user not found', function(done) {
|
||||
//
|
||||
// Set up the DB
|
||||
//
|
||||
context.jabber = new FakeDB(Fixtures.posts.userNotFound)
|
||||
//
|
||||
// Process the posts
|
||||
//
|
||||
posts(context).then(function(c) {
|
||||
expect(c).to.equal(context)
|
||||
expect(c.output.write.callCount).to.equal(1)
|
||||
let post = c.output.write.args[0][0]
|
||||
expect(post).to.deep.equal({
|
||||
type: 'post',
|
||||
post: {
|
||||
team: 'test',
|
||||
channel: 'uat-appsupport',
|
||||
user: 'micahel.cross',
|
||||
message: 'I meant thick',
|
||||
create_at: 1496693318263
|
||||
}
|
||||
})
|
||||
done()
|
||||
}).catch(function(e){
|
||||
expect(e).to.be.null
|
||||
done()
|
||||
})
|
||||
})
|
||||
|
||||
|
||||
it('should fail on body not found', function(done) {
|
||||
//
|
||||
// Set up the DB
|
||||
//
|
||||
context.jabber = new FakeDB(Fixtures.posts.bodyNotFound)
|
||||
//
|
||||
// Process the posts
|
||||
//
|
||||
posts(context).then(function(c) {
|
||||
expect(c).to.equal(context)
|
||||
expect(c.output.write.callCount).to.equal(0)
|
||||
done()
|
||||
}).catch(function(e){
|
||||
expect(e).to.be.null
|
||||
done()
|
||||
})
|
||||
})
|
||||
})
|
||||
18
lib/modules/test/sink.js
Normal file
18
lib/modules/test/sink.js
Normal file
@@ -0,0 +1,18 @@
|
||||
const { spy } = require('sinon')
|
||||
const { Writable } = require('stream')
|
||||
|
||||
//
|
||||
// Returns a spied writable stream
|
||||
//
|
||||
module.exports = function() {
|
||||
|
||||
var writable = new Writable({
|
||||
objectMode: true,
|
||||
write(chunk, encoding, callback) {
|
||||
return callback()
|
||||
}
|
||||
})
|
||||
spy(writable, 'write')
|
||||
|
||||
return writable
|
||||
}
|
||||
30
lib/modules/test/start.js
Normal file
30
lib/modules/test/start.js
Normal file
@@ -0,0 +1,30 @@
|
||||
const expect = require('chai').expect
|
||||
const fs = require('fs')
|
||||
const start = require('../start')
|
||||
const context = require('./context')()
|
||||
|
||||
describe('modules.start', function() {
|
||||
var resultHandler = function(err) {
|
||||
if(err) {
|
||||
console.log('unlink failed', err)
|
||||
} else {
|
||||
console.log('file deleted')
|
||||
}
|
||||
}
|
||||
|
||||
it('should set up the source and output', function(done) {
|
||||
start(context)
|
||||
.then(function (c) {
|
||||
expect(c).to.equal(context)
|
||||
expect(fs.existsSync(context.config.target.filename)).to.be.true
|
||||
done()
|
||||
})
|
||||
.catch(function(err){
|
||||
console.log(err)
|
||||
})
|
||||
})
|
||||
|
||||
afterEach(function() {
|
||||
fs.unlink(context.config.target.filename, resultHandler)
|
||||
})
|
||||
})
|
||||
27
lib/modules/test/team.js
Normal file
27
lib/modules/test/team.js
Normal file
@@ -0,0 +1,27 @@
|
||||
const expect = require('chai').expect
|
||||
const team = require('../team')
|
||||
const context = require('./context')()
|
||||
|
||||
describe('modules.team', function() {
|
||||
it('should write a team object', function(done) {
|
||||
team(context)
|
||||
.then(function (c) {
|
||||
expect(c).to.equal(context)
|
||||
expect(c.output.write.args[0][0]).to.deep.equal({
|
||||
type: 'team',
|
||||
team: {
|
||||
name: 'test',
|
||||
display_name: 'Test Team',
|
||||
description: 'Our Test Team',
|
||||
type: 'I',
|
||||
allow_open_invite: false
|
||||
}
|
||||
})
|
||||
done()
|
||||
})
|
||||
})
|
||||
|
||||
afterEach(function() {
|
||||
context.output.write.reset()
|
||||
})
|
||||
})
|
||||
88
lib/modules/test/users.js
Normal file
88
lib/modules/test/users.js
Normal file
@@ -0,0 +1,88 @@
|
||||
const expect = require('chai').expect
|
||||
const users = require('../users')
|
||||
const Fixtures = require('./fixtures')
|
||||
const context = require('./context')()
|
||||
|
||||
describe('modules.users', function() {
|
||||
|
||||
before(function(){
|
||||
context.values = {
|
||||
team: context.config.define.team,
|
||||
channels: {
|
||||
'admin@conference.example.com': {
|
||||
team: 'test',
|
||||
name: 'admin',
|
||||
display_name: 'Admin',
|
||||
header: 'Admin Test room',
|
||||
purpose: 'Admin Test room',
|
||||
type: 'O'
|
||||
},
|
||||
'uat-appsupport@conference.example.com': {
|
||||
team: 'hsin',
|
||||
name: 'uat-appsupport',
|
||||
display_name: 'Uat Appsupport',
|
||||
header: '',
|
||||
purpose: '',
|
||||
type: 'P'
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
it('should process user objects', function(done) {
|
||||
|
||||
context.jabber.fetch.returns(Promise.resolve({recordset: Fixtures.users}))
|
||||
|
||||
users(context).then(function(c) {
|
||||
expect(c).to.equal(context)
|
||||
expect(Object.keys(c.values.users).length).equals(13)
|
||||
expect(c.output.write.args[0][0]).to.deep.equal({
|
||||
type: 'user',
|
||||
user: {
|
||||
username: 'micahel.cross',
|
||||
email: 'micahel.cross@example.com',
|
||||
auth_service: 'ldap',
|
||||
auth_data: 'MICAHEL.CROSS',
|
||||
teams: [
|
||||
{
|
||||
name: 'test',
|
||||
channels: [
|
||||
{
|
||||
name: 'admin'
|
||||
}, {
|
||||
name: 'uat-appsupport'
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
})
|
||||
expect(c.output.write.args[1][0]).to.deep.equal({
|
||||
type: 'user',
|
||||
user: {
|
||||
username: 'sbarclay',
|
||||
email: 'sbarclay@example.com',
|
||||
auth_service: 'ldap',
|
||||
auth_data: 'SBARCLAY',
|
||||
teams: [
|
||||
{
|
||||
name: 'test',
|
||||
channels: [
|
||||
{
|
||||
name: 'admin'
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
})
|
||||
|
||||
done()
|
||||
})
|
||||
})
|
||||
|
||||
afterEach(function() {
|
||||
context.jabber.fetch.reset()
|
||||
context.output.write.reset()
|
||||
})
|
||||
})
|
||||
21
lib/modules/test/version.js
Normal file
21
lib/modules/test/version.js
Normal file
@@ -0,0 +1,21 @@
|
||||
const expect = require('chai').expect
|
||||
const version = require('../version')
|
||||
const context = require('./context')()
|
||||
|
||||
describe('modules.version', function() {
|
||||
it('should write a version object', function(done) {
|
||||
version(context)
|
||||
.then(function (c) {
|
||||
expect(c).to.equal(context)
|
||||
expect(c.output.write.args[0][0]).to.deep.equal({
|
||||
type: 'version',
|
||||
version: 1
|
||||
})
|
||||
done()
|
||||
})
|
||||
})
|
||||
|
||||
afterEach(function() {
|
||||
context.output.write.reset()
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user