Add jasmine for message-processor

This commit is contained in:
Juan Tejada 2016-06-24 10:35:13 -07:00
parent b67a3ae3e4
commit 0ac3c8c313
4 changed files with 33 additions and 21 deletions

View file

@ -5,8 +5,19 @@
"main": "index.js",
"author": "Nylas",
"license": "ISC",
"scripts": {
"test": "babel-node spec/run.js"
},
"dependencies": {
"mailparser": "0.6.0",
"nylas-core": "0.x.x"
},
"devDependencies": {
"babel-cli": "^6.10.1",
"babel-preset-es2015": "^6.9.0",
"jasmine": "^2.4.1"
},
"babel": {
"presets": ["es2015"]
}
}

View file

@ -1,35 +1,24 @@
const path = require('path')
const fs = require('fs')
const assert = require('assert')
const {processMessage} = require('../processors/parsing')
const BASE_PATH = path.join('/', 'Users', 'juan', 'Downloads', 'sample data')
const tests = []
function it(name, testFn) {
tests.push(testFn)
}
function test() {
tests.reduce((prev, t) => prev.then(() => t()), Promise.resolve())
.then(() => console.log('Success!'))
.catch((err) => console.log(err))
}
it('parses the message correctly', () => {
it('parses the message correctly', (done) => {
const bodyPath = path.join(BASE_PATH, '1-99174-body.txt')
const headersPath = path.join(BASE_PATH, '1-99174-headers.txt')
const rawBody = fs.readFileSync(bodyPath, 'utf8')
const rawHeaders = fs.readFileSync(headersPath, 'utf8')
const message = { rawHeaders, rawBody }
return processMessage({message}).then((processed) => {
const bodyPart = `<p>In <a href="https://github.com/electron/electron.atom.io/pull/352#discussion_r67715160">_data/apps.yml</a>:</p>`
assert.equal(processed.headers['in-reply-to'], '<electron/electron.atom.io/pull/352@github.com>')
assert.equal(processed.messageId, '<electron/electron.atom.io/pull/352/r67715160@github.com>')
assert.equal(processed.subject, 'Re: [electron/electron.atom.io] Add Jasper app (#352)')
assert.equal(processed.body.includes(bodyPart), true)
processMessage({message}).then((processed) => {
expect(true).toBe(false)
expect(processed.headers['in-reply-to']).toEqual('<electron/electron.atom.io/pull/352@github.com>')
expect(processed.messageId).toEqual('<electron/electron.atom.io/pull/352/r67715160@github.com>')
expect(processed.subject).toEqual('Re: [electron/electron.atom.io] Add Jasper app (#352)')
expect(processed.body.includes(bodyPart)).toBe(true)
done()
})
})
test()

View file

@ -0,0 +1,5 @@
import Jasmine from 'jasmine'
const jasmine = new Jasmine()
jasmine.loadConfigFile('spec/support/jasmine.json')
jasmine.execute()

View file

@ -0,0 +1,7 @@
{
"spec_dir": "spec",
"spec_files": [
"**/*-spec.js"
],
"helpers": [ ]
}