This repository has been archived by the owner. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from robinjoseph08/add-testing
test(regex): add tests and travis
- Loading branch information
Showing
12 changed files
with
258 additions
and
3 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
language: node_js | ||
sudo: false | ||
node_js: | ||
- '5' | ||
addons: | ||
postgresql: '9.4' | ||
services: | ||
- postgresql | ||
before_script: | ||
- psql -c 'CREATE ROLE "rmj_user" CREATEDB CREATEUSER LOGIN;' -U postgres | ||
- createdb -O rmj_user rmj | ||
- npm run migrate | ||
script: | ||
- npm test | ||
- npm run lint | ||
after_script: | ||
- npm run coveralls |
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,11 +1,11 @@ | ||
'use strict'; | ||
|
||
module.exports = { | ||
DB_NAME: 'ubuntu', | ||
DB_NAME: 'rmj', | ||
DB_HOST: 'localhost', | ||
DB_PORT: 5432, | ||
DB_PASSWORD: '', | ||
DB_USER: 'ubuntu', | ||
DB_USER: 'rmj_user', | ||
DRAIN_TIMEOUT: 5000, | ||
PORT: 8080 | ||
}; |
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 |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"id": 1 | ||
} |
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 |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"id": 1, | ||
"value": "left_test", | ||
"side": "left", | ||
"regex_level_id": 1 | ||
} |
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 |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"id": 2, | ||
"value": "right_test", | ||
"side": "right", | ||
"regex_level_id": 1 | ||
} |
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 |
---|---|---|
@@ -0,0 +1,90 @@ | ||
'use strict'; | ||
|
||
let expect = require('chai').expect; | ||
|
||
let Knex = require('../../../app/libraries/knex'); | ||
let RegexLevel = require('../../../app/models/regex/level'); | ||
let RegexWord = require('../../../app/models/regex/word'); | ||
|
||
let defaultLevel = require('../../fixtures/regex/levels/default'); | ||
let leftWord = require('../../fixtures/regex/words/left'); | ||
let rightWord = require('../../fixtures/regex/words/right'); | ||
|
||
describe('regex level model', () => { | ||
|
||
beforeEach(() => { | ||
return Promise.all([ | ||
Knex.raw('TRUNCATE regex_levels CASCADE'), | ||
Knex.raw('TRUNCATE regex_words CASCADE') | ||
]) | ||
.then(() => { | ||
return Knex('regex_levels').insert(defaultLevel); | ||
}) | ||
.then(() => { | ||
return Knex('regex_words').insert([leftWord, rightWord]); | ||
}); | ||
}); | ||
|
||
describe('left_words', () => { | ||
|
||
it('only lists left words', () => { | ||
return new RegexLevel({ id: defaultLevel.id }) | ||
.fetch({ withRelated: ['left_words'] }) | ||
.then((level) => { | ||
expect(level.related('left_words')).to.have.length(1); | ||
expect(level.related('left_words').at(0).get('id')).to.eql(leftWord.id); | ||
}); | ||
}); | ||
|
||
}); | ||
|
||
describe('right_words', () => { | ||
|
||
it('only lists right words', () => { | ||
return new RegexLevel({ id: defaultLevel.id }) | ||
.fetch({ withRelated: ['right_words'] }) | ||
.then((level) => { | ||
expect(level.related('right_words')).to.have.length(1); | ||
expect(level.related('right_words').at(0).get('id')).to.eql(rightWord.id); | ||
}); | ||
}); | ||
|
||
}); | ||
|
||
describe('serialize', () => { | ||
|
||
let left; | ||
let right; | ||
let level; | ||
|
||
beforeEach(() => { | ||
left = RegexWord.collection([ | ||
RegexWord.forge({ id: 1, value: 'testing1', side: 'left' }), | ||
RegexWord.forge({ id: 2, value: 'testing2', side: 'left' }) | ||
]); | ||
right = RegexWord.collection([ | ||
RegexWord.forge({ id: 3, value: 'testing3', side: 'right' }), | ||
RegexWord.forge({ id: 4, value: 'testing4', side: 'right' }), | ||
RegexWord.forge({ id: 5, value: 'testing5', side: 'right' }) | ||
]); | ||
level = RegexLevel.forge({ id: 1 }); | ||
level.relations.left_words = left; | ||
level.relations.right_words = right; | ||
}); | ||
|
||
it('returns the correct properties', () => { | ||
let json = level.serialize(); | ||
|
||
expect(json).to.have.all.keys('id', 'left_words', 'right_words'); | ||
expect(json.id).to.eql(level.get('id')); | ||
left.each((word, i) => { | ||
expect(json.left_words[i]).to.eql(word.serialize()); | ||
}); | ||
right.each((word, i) => { | ||
expect(json.right_words[i]).to.eql(word.serialize()); | ||
}); | ||
}); | ||
|
||
}); | ||
|
||
}); |
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 |
---|---|---|
@@ -0,0 +1,28 @@ | ||
'use strict'; | ||
|
||
let expect = require('chai').expect; | ||
|
||
let RegexWord = require('../../../app/models/regex/word'); | ||
|
||
describe('regex word model', () => { | ||
|
||
let word; | ||
|
||
beforeEach(() => { | ||
word = RegexWord.forge({ id: 1, value: 'testing', side: 'left' }); | ||
}); | ||
|
||
describe('serialize', () => { | ||
|
||
it('returns the correct properties', () => { | ||
let json = word.serialize(); | ||
|
||
expect(json).to.have.all.keys('id', 'value', 'side'); | ||
expect(json.id).to.eql(word.get('id')); | ||
expect(json.value).to.eql(word.get('value')); | ||
expect(json.side).to.eql(word.get('side')); | ||
}); | ||
|
||
}); | ||
|
||
}); |
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 |
---|---|---|
@@ -0,0 +1,39 @@ | ||
'use strict'; | ||
|
||
let expect = require('chai').expect; | ||
|
||
let Controller = require('../../../../app/plugins/features/regex/controller'); | ||
let Knex = require('../../../../app/libraries/knex'); | ||
|
||
let defaultLevel = require('../../../fixtures/regex/levels/default'); | ||
let leftWord = require('../../../fixtures/regex/words/left'); | ||
let rightWord = require('../../../fixtures/regex/words/right'); | ||
|
||
describe('regex controller', () => { | ||
|
||
beforeEach(() => { | ||
return Promise.all([ | ||
Knex.raw('TRUNCATE regex_levels CASCADE'), | ||
Knex.raw('TRUNCATE regex_words CASCADE') | ||
]) | ||
.then(() => { | ||
return Knex('regex_levels').insert(defaultLevel); | ||
}) | ||
.then(() => { | ||
return Knex('regex_words').insert([leftWord, rightWord]); | ||
}); | ||
}); | ||
|
||
describe('list', () => { | ||
|
||
it('gets all regex levels', () => { | ||
return Controller.list() | ||
.then((levels) => { | ||
expect(levels).to.have.length(1); | ||
expect(levels.at(0).get('id')).to.eql(defaultLevel.id); | ||
}); | ||
}); | ||
|
||
}); | ||
|
||
}); |
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 |
---|---|---|
@@ -0,0 +1,43 @@ | ||
'use strict'; | ||
|
||
let expect = require('chai').expect; | ||
|
||
let Knex = require('../../../../app/libraries/knex'); | ||
let Server = require('../../../../app/server'); | ||
|
||
let defaultLevel = require('../../../fixtures/regex/levels/default'); | ||
let leftWord = require('../../../fixtures/regex/words/left'); | ||
let rightWord = require('../../../fixtures/regex/words/right'); | ||
|
||
describe('regex integration', () => { | ||
|
||
beforeEach(() => { | ||
return Promise.all([ | ||
Knex.raw('TRUNCATE regex_levels CASCADE'), | ||
Knex.raw('TRUNCATE regex_words CASCADE') | ||
]) | ||
.then(() => { | ||
return Knex('regex_levels').insert(defaultLevel); | ||
}) | ||
.then(() => { | ||
return Knex('regex_words').insert([leftWord, rightWord]); | ||
}); | ||
}); | ||
|
||
describe('list', () => { | ||
|
||
it('correctly retrieves and serializes', () => { | ||
return Server.injectThen({ | ||
url: '/regex', | ||
method: 'GET' | ||
}) | ||
.then((res) => { | ||
expect(res.statusCode).to.eql(200); | ||
expect(res.result).to.have.length(1); | ||
expect(res.result[0].id).to.eql(defaultLevel.id); | ||
}); | ||
}); | ||
|
||
}); | ||
|
||
}); |
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 |
---|---|---|
@@ -0,0 +1,11 @@ | ||
'use strict'; | ||
|
||
var Server = require('../app/server'); | ||
|
||
Server.register([ | ||
require('inject-then') | ||
], (err) => { | ||
if (err) { | ||
throw err; | ||
} | ||
}); |