-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathFacebookModuleTest.js
More file actions
63 lines (56 loc) · 2.05 KB
/
Copy pathFacebookModuleTest.js
File metadata and controls
63 lines (56 loc) · 2.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
/*!
* Expanse, LLC
* http://expansellc.io
*
* Copyright 2016
* Released under the Apache 2 license
* https://www.apache.org/licenses/LICENSE-2.0
*
* @authors Ryan Scott
*/
'use strict';
const expect = require('chai').expect;
const nock = require('nock');
const ProviderConfig = require('../config/ProviderConfig');
const FacebookIdModule = require('../lib/FacebookIdModule');
describe('FacebookIdModule Unit Tests', () => {
const faceMod = new FacebookIdModule(new ProviderConfig());
const goodToken = 'good';
const invalidToken = 'invalid';
const expectedPrincipalId = 'jenkypenky@facebook.com';
const validFacePayload = '{"data": {"app_id": "application.identifier","application": "ExpanseIO Test App","expires_at": 1473112800,"is_valid": true,"scopes": ["email","public_profile"],"user_id": "jenkypenky@facebook.com"}}';
const invalidFacePayload = {
error_description: 'Mock Invalid Value'
};
/** see this projects README for the Facebook Token Contract **/
it('Mock 200 Response from Facebook Token API to FacebookIdModule', () => {
nock('https://graph.facebook.com')
.get('/debug_token')
.query({
input_token: goodToken,
access_token: 'APPID_REPLACE_ME|SECRET_SSHHH'
})
.reply(200, validFacePayload);
const result = faceMod.callIdProvider(goodToken);
return result.then(data => {
expect(data).to.equal(expectedPrincipalId);
});
});
it('Mock 400 Response from Facebook Token API to FacebookIdModule', () => {
nock('https://graph.facebook.com')
.get('/debug_token')
.query({
input_token: invalidToken,
access_token: 'APPID_REPLACE_ME|SECRET_SSHHH'
})
.reply(400, invalidFacePayload);
const result = faceMod.callIdProvider(invalidToken);
return result.catch(error => {
expect(error).to.equal(0);
});
});
it('A PrincipalId Should Be Derived from the Facebook Token Response', () => {
const principalId = FacebookIdModule.retrievePrincipalId(validFacePayload);
expect(principalId).to.equal(expectedPrincipalId);
});
});