Skip to content

Instantly share code, notes, and snippets.

@reharik
Created March 3, 2017 14:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save reharik/f79b2de15cf868c28bb62b0e087ee3c7 to your computer and use it in GitHub Desktop.
Save reharik/f79b2de15cf868c28bb62b0e087ee3c7 to your computer and use it in GitHub Desktop.
async activity(ctx) {
let activitySql = path.join(__dirname,`./../repositories/sql/activity.sql`);
let activity = await repository(activitySql,'get_activity_by_id', ctx.params);
ctx.status = 200;
ctx.body = {
status: ctx.status,
success: true,
data: activity
};
return ctx;
}
describe('Container Test', function() {
let mut;
let repositoryStub;
let activity;
let ctx1;
before(function () {
// set up mock for repo
repositoryStub = td.function('repository');
});
beforeEach(() => {
ctx1 = {params: {id: 1}};
activity = {
id: 123,
title: "hello"
};
});
describe('#ACTIVITY CONTROLLER', () => {
describe('ACTIVITY', function () {
context('when calling activity get', function () {
it('should call repo', async function () {
let activitySql = path.join(__dirname,`./../../src/repositories/sql/activity.sql`);
td.when(repositoryStub(activitySql, 'get_activity_by_id', ctx1.params)).thenReturn(activity);
let result = await mut.activity(ctx1);
console.log(`==========td.explain(repositoryStub)=========`);
console.log(td.explain(repositoryStub));
console.log(`==========END td.explain(repositoryStub)=========`);
td.verify(repositoryStub);
});
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment