Skip to content

Commit

Permalink
Convert share controller test to tap.
Browse files Browse the repository at this point in the history
brianloveswords committed Nov 16, 2012

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
1 parent 0a0974a commit a3eb9ad
Showing 3 changed files with 53 additions and 79 deletions.
1 change: 1 addition & 0 deletions controllers/share.js
Original file line number Diff line number Diff line change
@@ -155,6 +155,7 @@ exports.createOrUpdate = function (request, response) {
var stories = {};
var submitted = request.body;

// #TODO: don't assume any stories have been submitted
for (var i = 0; i < submitted.stories.length; i++)
if (submitted.stories[i]) stories[i] = submitted.stories[i];

79 changes: 0 additions & 79 deletions test/share-controller-test.js

This file was deleted.

52 changes: 52 additions & 0 deletions test/share-controller.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
const test = require('tap').test;
const testUtils = require('./');
const conmock = require('./conmock');
const share = require('../controllers/share');

const User = require('../models/user');
const Badge = require('../models/badge');
const Group = require('../models/group');

testUtils.prepareDatabase({
'1-user': new User({ email: '[email protected]' }),
'2-other-user': new User({ email: '[email protected]' }),
'3-badge': new Badge({
user_id: 1,
type: 'hosted',
endpoint: 'endpoint',
image_path: 'image_path',
body_hash: 'body_hash',
body: testUtils.makeAssertion()
}),
'4-group': new Group({
user_id: 1,
name: 'name',
url: 'url',
'public': 0,
badges: [1]
}),
}, function (fixtures) {
test('share#createOrUpdate: no user', function (t) {
conmock(share.createOrUpdate, function (err, mock) {
t.same(mock.status, 403, 'should be forbidden');
t.end();
});
});

test('share#createOrUpdate: wrong user', function (t) {
const user = fixtures['2-other-user'];
const group = fixtures['4-group'];
const request = { user: user, group: group }
conmock({
handler: share.createOrUpdate,
request: request,
}, function (err, mock) {
t.same(mock.status, 403, 'should be forbidden');
t.end();
});
});

testUtils.finish(test);
});


0 comments on commit a3eb9ad

Please sign in to comment.