Skip to content
Snippets Groups Projects
Commit 2b476135 authored by Tamás Szabó's avatar Tamás Szabó
Browse files

tests

parent 4b1e2480
Branches master
No related tags found
No related merge requests found
const expect = require('chai').expect;
const getSerieMW = require('../../middleware/episode/getEpisode');
describe('getEpisode ', () => {
it('should connect to database', (done) => {
const req = {
params: {
episodeId: 10
}
};
const res = {
tpl: {
episode: {
name: 'asd'
}
}
};
const mockEpisodeModel = {
findById: (id) => ({
then: (then) => {
then({ name: 'asd' }, undefined);
}
})
};
getSerieMW({ episodeModel: mockEpisodeModel })(req, res, (err) => {
expect(res.tpl.episodeId).to.eql(10);
expect(res.tpl.episode).to.have.property('name');
expect(res.tpl.episode.name).to.eql('asd');
expect(res.tpl.episode).to.not.have.property('asd');
done();
})
});
it('should not connect to database', (done) => {
const req = {
params: {
id: 10
}
};
const res = {
tpl: {
episode: {
name: 'asd'
}
},
redirect: (to) => ({ to })
};
const mockEpisodeModel = {
findById: (id) => ({
then: (then, err) => {
then()
return {
catch: (er) => {
return er()
}
}
}
})
};
getSerieMW({ episodeModel: mockEpisodeModel })(req, res, (err) => {
expect(res).to.have.property('redirect');
done();
})
});
});
...@@ -17,9 +17,8 @@ describe('getSerie ', () => { ...@@ -17,9 +17,8 @@ describe('getSerie ', () => {
}; };
const mockSerieModel = { const mockSerieModel = {
findById: (id) => ({ findById: (id) => ({
then: (then, error) => { then: (then) => {
then({ name: 'asd' }, undefined); then({ name: 'asd' }, undefined);
error()
} }
}) })
}; };
...@@ -27,6 +26,40 @@ describe('getSerie ', () => { ...@@ -27,6 +26,40 @@ describe('getSerie ', () => {
expect(res.tpl.serieId).to.eql(10); expect(res.tpl.serieId).to.eql(10);
expect(res.tpl.serie).to.have.property('name'); expect(res.tpl.serie).to.have.property('name');
expect(res.tpl.serie.name).to.eql('asd'); expect(res.tpl.serie.name).to.eql('asd');
expect(res.tpl.serie).to.not.have.property('asd');
done();
})
});
it('should not connect to database', (done) => {
const req = {
params: {
id: 10
}
};
const res = {
tpl: {
serie: {
name: 'asd'
}
},
redirect: (to) => ({ to })
};
const mockSerieModel = {
findById: (id) => ({
then: (then, err) => {
then()
return {
catch: (er) => {
return er()
}
}
}
})
};
getSerieMW({ serieModel: mockSerieModel })(req, res, (err) => {
expect(res).to.have.property('redirect');
done(); done();
}) })
}); });
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment