-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update the NodeJS got module to latest version (#20)
* Update Node to lts/iron in devcontainer * Update ex-02 dependencies, bump got version, upd code/tests * Update ex-04 dep, bump got, update code and tests * Update ex-05 dep, bump got, upd code/tests * Update ex-09 dep, dump got, update code/tests * Upd ex-10 dep for client and api. Bump got, update code/tests * Update ex-11, part 1 (missing obo for episodes) * Upd ex-11, episodes, got o-b-o, code, tests - fixed prehandler to avoid resends
- Loading branch information
Showing
52 changed files
with
9,210 additions
and
11,296 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 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
Large diffs are not rendered by default.
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
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 |
---|---|---|
|
@@ -10,25 +10,26 @@ const { test } = require('tap'); | |
const authUtils = require('../lib/auth-utils.js'); | ||
var __ = require('underscore'); | ||
var sinon = require('sinon'); | ||
const got = require('got'); | ||
const { getGot, resetGot } = require('./gotHelper.js'); | ||
|
||
test('Request access token should respond with access token', async (t) => { | ||
|
||
test('Request accesstoken should respond with access token', async (t) => { | ||
|
||
const authCode = '1234' | ||
|
||
//Creating response object, some objects are strings of JSON! | ||
const responseObject = {"body" : '{"access_token": "eyABCDE"}'}; | ||
const responseObject = {body : {access_token: 'eyABCDE'}}; | ||
|
||
sinon.stub(got,'post'); | ||
got.post.callsFake(async function() { | ||
return responseObject; | ||
}); | ||
// Reset got instance before stubbing | ||
resetGot(); | ||
|
||
const got = await getGot(); | ||
sinon.stub(got, 'post').resolves(responseObject); | ||
|
||
var accessToken = await authUtils.requestAccessTokenUsingAuthCode( | ||
authCode | ||
); | ||
authCode | ||
); | ||
|
||
console.log('AT: ' + accessToken); | ||
console.log('AT: ' + accessToken); | ||
|
||
t.ok((__.size(accessToken) > 0), 'Access token received'); | ||
t.ok(__.isString(accessToken),'Access token should be string'); | ||
|
@@ -42,9 +43,11 @@ test('Request accesstoken should respond with access token', async (t) => { | |
test('Failed request to aquire access token should fail', async (t) => { | ||
const authCode = '1234'; | ||
|
||
|
||
sinon.stub(got, 'get'); | ||
got.get.throws("Test: Error from request to token endpoint"); | ||
// Reset got instance before stubbing | ||
resetGot(); | ||
|
||
const got = await getGot(); | ||
sinon.stub(got, 'get').throws(new Error("Test: Error from request to token endpoint")); | ||
|
||
var accessToken = await authUtils.requestAccessTokenUsingAuthCode(authCode); | ||
|
||
|
@@ -58,38 +61,39 @@ test('Failed request to aquire access token should fail', async (t) => { | |
|
||
|
||
test('Request to read inbox should return inbox content', async (t) => { | ||
|
||
const accessToken = 'eyABCDE'; | ||
const emailReturnObject = { | ||
"value": [ | ||
{ | ||
"subject": "Test Melding 1", | ||
"sender": { | ||
"emailAddress": { | ||
"name": "Robert Knallert", | ||
"address": "[email protected]" | ||
} | ||
"value": [ | ||
{ | ||
"subject": "Test Melding 1", | ||
"sender": { | ||
"emailAddress": { | ||
"name": "Robert Knallert", | ||
"address": "[email protected]" | ||
} | ||
}, | ||
{ | ||
"subject": "Test Melding 2", | ||
"sender": { | ||
"emailAddress": { | ||
"name": "Jon Snow", | ||
"address": "[email protected]" | ||
} | ||
} | ||
}, | ||
{ | ||
"subject": "Test Melding 2", | ||
"sender": { | ||
"emailAddress": { | ||
"name": "Jon Snow", | ||
"address": "[email protected]" | ||
} | ||
} | ||
] | ||
|
||
} | ||
] | ||
}; | ||
|
||
const responseObject = { body: JSON.stringify(emailReturnObject) }; | ||
// Mock response object | ||
const responseObject = { body: emailReturnObject }; | ||
|
||
sinon.stub(got, 'get'); | ||
got.get.callsFake(async function () { | ||
return responseObject; | ||
}); | ||
// Reset got instance before stubbing | ||
resetGot(); | ||
|
||
// Get the got instance and stub the get method | ||
const got = await getGot(); | ||
sinon.stub(got, 'get').resolves(responseObject); | ||
|
||
var newMails = await authUtils.readInbox(accessToken); | ||
|
||
|
@@ -105,13 +109,17 @@ test('Request to read inbox should return inbox content', async (t) => { | |
|
||
test('Request to read inbox should return empty when error', async (t) => { | ||
const accessToken = 'eyABCDE'; | ||
|
||
sinon.stub(got, 'get'); | ||
got.get.throws('Test: Error from request to ms graph inbox'); | ||
|
||
// Reset got instance before stubbing | ||
resetGot(); | ||
|
||
// Get the got instance and stub the get method to throw an error | ||
const got = await getGot(); | ||
sinon.stub(got, 'get').throws(new Error('Test: Error from request to ms graph inbox')); | ||
|
||
var newMails = await authUtils.readInbox(accessToken); | ||
t.ok(__.size(newMails) == 0, 'Empty array of new mails received'); | ||
|
||
t.ok(__.size(newMails) === 0, 'Empty array of new mails received'); | ||
t.ok(__.isArray(newMails), 'New mails should be in array'); | ||
|
||
got.get.restore(); | ||
|
@@ -157,6 +165,4 @@ test('user-agent header should be correct', async (t) => { | |
|
||
t.end(); | ||
}); | ||
|
||
t.end(); | ||
}); | ||
}); |
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,16 @@ | ||
let gotInstance; | ||
|
||
async function getGot() { | ||
if (!gotInstance) { | ||
const got = await import('got'); | ||
gotInstance = got.default; | ||
} | ||
return gotInstance; | ||
} | ||
|
||
// For testing purposes: Allow resetting gotInstance | ||
function resetGot() { | ||
gotInstance = null; | ||
} | ||
|
||
module.exports = { getGot, resetGot }; |
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
Oops, something went wrong.