Skip to content
Snippets Groups Projects
Commit ea26977b authored by Vytor Calixto's avatar Vytor Calixto :space_invader:
Browse files

:white_check_mark: Add tests to id2str

parent e83c405e
No related branches found
No related tags found
3 merge requests!116Release v1.0.0,!44Feature multiple where,!35Feature id2str
Pipeline #
process.env.NODE_ENV = 'test';
const chai = require('chai');
const dirtyChai = require('dirty-chai');
chai.use(dirtyChai);
const chaiXml = require('chai-xml');
chai.use(chaiXml);
const chaiHttp = require('chai-http');
const assert = chai.assert;
const expect = chai.expect;
const should = chai.should(); // actually call the function
const libs = `${process.cwd()}/libs`;
const server = require(`${libs}/app`);
const id2str = require(`${libs}/middlewares/id2str`);
chai.use(chaiHttp);
describe('id2str middleware', () => {
let req, res;
it('should return a function', (done) => {
expect(id2str.transform).to.be.a.Function;
done();
});
it('should transform a gender id', (done) => {
expect(id2str.gender(1)).to.deep.equal('Masculino');
done();
});
it('should transform a period id', (done) => {
expect(id2str.period(1)).to.deep.equal('Diurno');
done();
});
it('should transform a school year id', (done) => {
expect(id2str.schoolYear(11)).to.deep.equal('Creche - Menor de 1 ano');
done();
});
it('should transform a result', (done) => {
let req = {
result: [{gender_id: 2, period_id: 3, school_year_id: 11}]
};
id2str.transform(false)(req, {}, (error)=>{
if (error) { throw new Error('Expected not to receive an error'); }
req.should.have.property('result');
req.result.should.not.be.undefined;
req.result.should.be.deep.equal([{gender_id: 2, period_id: 3, school_year_id: 11, gender_name: 'Feminino', period_name: 'Integral', school_year_name: 'Creche - Menor de 1 ano'}]);
done();
});
});
it('should transform a result and delete the ids', (done) => {
let req = {
result: [{gender_id: 2, period_id: 3, school_year_id: 11}]
};
id2str.transform(true)(req, {}, (error)=>{
if (error) { throw new Error('Expected not to receive an error'); }
req.should.have.property('result');
req.result.should.not.be.undefined;
req.result.should.be.deep.equal([{gender_name: 'Feminino', period_name: 'Integral', school_year_name: 'Creche - Menor de 1 ano'}]);
done();
});
});
});
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment