forked from mozilla/openbadges-backpack
-
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.
Convert share controller test to tap.
1 parent
0a0974a
commit a3eb9ad
Showing
3 changed files
with
53 additions
and
79 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
This file was deleted.
Oops, something went wrong.
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,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); | ||
}); | ||
|
||
|