Skip to content

Commit

Permalink
Merge pull request #639 from Accenture/task/638-ensure-test-cases-don…
Browse files Browse the repository at this point in the history
…t-fail-on-api-request-count-due-to-tokens

#638: ensure token requests are not counted
  • Loading branch information
JoernBerkefeld authored Jan 19, 2023
2 parents 5821741 + f3e4e1a commit 0009c13
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 36 deletions.
20 changes: 10 additions & 10 deletions test/dataExtension.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ describe('dataExtension', () => {
'returned metadata was not equal expected'
);
assert.equal(
Object.values(testUtils.getAPIHistory()).flat().length,
6,
'Unexpected number of requests made'
testUtils.getAPIHistoryLength(),
5,
'Unexpected number of requests made. Run testUtils.getAPIHistoryDebug() to see the requests'
);
return;
});
Expand Down Expand Up @@ -65,9 +65,9 @@ describe('dataExtension', () => {
'returned metadata was not equal expected for update'
);
assert.equal(
Object.values(testUtils.getAPIHistory()).flat().length,
12,
'Unexpected number of requests made'
testUtils.getAPIHistoryLength(),
11,
'Unexpected number of requests made. Run testUtils.getAPIHistoryDebug() to see the requests'
);
return;
});
Expand Down Expand Up @@ -112,9 +112,9 @@ describe('dataExtension', () => {
'returned deployment file was not equal expected'
);
assert.equal(
Object.values(testUtils.getAPIHistory()).flat().length,
testUtils.getAPIHistoryLength(),
5,
'Unexpected number of requests made'
'Unexpected number of requests made. Run testUtils.getAPIHistoryDebug() to see the requests'
);
return;
});
Expand Down Expand Up @@ -159,9 +159,9 @@ describe('dataExtension', () => {
'returned deployment file was not equal expected'
);
assert.equal(
Object.values(testUtils.getAPIHistory()).flat().length,
testUtils.getAPIHistoryLength(),
5,
'Unexpected number of requests made'
'Unexpected number of requests made. Run testUtils.getAPIHistoryDebug() to see the requests'
);
return;
});
Expand Down
16 changes: 8 additions & 8 deletions test/query.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ describe('query', () => {
file(testUtils.getExpectedFile('9999999', 'query', 'get', 'sql'))
);
assert.equal(
Object.values(testUtils.getAPIHistory()).flat().length,
testUtils.getAPIHistoryLength(),
6,
'Unexpected number of requests made'
'Unexpected number of requests made. Run testUtils.getAPIHistoryDebug() to see the requests'
);
return;
});
Expand Down Expand Up @@ -80,9 +80,9 @@ describe('query', () => {
);
// check number of API calls
assert.equal(
Object.values(testUtils.getAPIHistory()).flat().length,
testUtils.getAPIHistoryLength(),
8,
'Unexpected number of requests made'
'Unexpected number of requests made. Run testUtils.getAPIHistoryDebug() to see the requests'
);
return;
});
Expand Down Expand Up @@ -126,9 +126,9 @@ describe('query', () => {
file(testUtils.getActualDeployFile('testExistingQuery', 'query', 'sql'))
).to.equal(file(testUtils.getExpectedFile('9999999', 'query', 'build', 'sql')));
assert.equal(
Object.values(testUtils.getAPIHistory()).flat().length,
testUtils.getAPIHistoryLength(),
6,
'Unexpected number of requests made'
'Unexpected number of requests made. Run testUtils.getAPIHistoryDebug() to see the requests'
);
return;
});
Expand Down Expand Up @@ -173,9 +173,9 @@ describe('query', () => {
).to.equal(file(testUtils.getExpectedFile('9999999', 'query', 'build', 'sql')));

assert.equal(
Object.values(testUtils.getAPIHistory()).flat().length,
testUtils.getAPIHistoryLength(),
6,
'Unexpected number of requests made'
'Unexpected number of requests made. Run testUtils.getAPIHistoryDebug() to see the requests'
);
return;
});
Expand Down
12 changes: 6 additions & 6 deletions test/transactionalEmail.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ describe('transactionalEmail', () => {
'returned JSON was not equal expected'
);
assert.equal(
Object.values(testUtils.getAPIHistory()).flat().length,
testUtils.getAPIHistoryLength(),
12,
'Unexpected number of requests made'
'Unexpected number of requests made. Run testUtils.getAPIHistoryDebug() to see the requests'
);
return;
});
Expand Down Expand Up @@ -68,9 +68,9 @@ describe('transactionalEmail', () => {
);
// check number of API calls
assert.equal(
Object.values(testUtils.getAPIHistory()).flat().length,
testUtils.getAPIHistoryLength(),
13,
'Unexpected number of requests made'
'Unexpected number of requests made. Run testUtils.getAPIHistoryDebug() to see the requests'
);
return;
});
Expand Down Expand Up @@ -110,9 +110,9 @@ describe('transactionalEmail', () => {
'returned deployment JSON was not equal expected'
);
assert.equal(
Object.values(testUtils.getAPIHistory()).flat().length,
testUtils.getAPIHistoryLength(),
12,
'Unexpected number of requests made'
'Unexpected number of requests made. Run testUtils.getAPIHistoryDebug() to see the requests'
);
return;
});
Expand Down
14 changes: 8 additions & 6 deletions test/transactionalPush.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ describe('transactionalPush', () => {
'returned JSON was not equal expected'
);
assert.equal(
Object.values(testUtils.getAPIHistory()).flat().length,
testUtils.getAPIHistoryLength(),
3,
'Unexpected number of requests made'
'Unexpected number of requests made. Run testUtils.getAPIHistoryDebug() to see the requests'
);
return;
});
Expand Down Expand Up @@ -68,9 +68,10 @@ describe('transactionalPush', () => {
);
// check number of API calls
assert.equal(
Object.values(testUtils.getAPIHistory()).flat().length,
testUtils.getAPIHistoryLength(),
4,
'Unexpected number of requests made'
'Unexpected number of requests made. Run testUtils.getAPIHistoryDebug() to see the requests',
testUtils.getAPIHistoryDebug()
);
return;
});
Expand Down Expand Up @@ -110,9 +111,10 @@ describe('transactionalPush', () => {
'returned deployment JSON was not equal expected'
);
assert.equal(
Object.values(testUtils.getAPIHistory()).flat().length,
testUtils.getAPIHistoryLength(),
3,
'Unexpected number of requests made'
'Unexpected number of requests made. Run testUtils.getAPIHistoryDebug() to see the requests',
testUtils.getAPIHistoryDebug()
);
return;
});
Expand Down
12 changes: 6 additions & 6 deletions test/transactionalSMS.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ describe('transactionalSMS', () => {
file(testUtils.getExpectedFile('9999999', 'transactionalSMS', 'get', 'amp'))
);
assert.equal(
Object.values(testUtils.getAPIHistory()).flat().length,
testUtils.getAPIHistoryLength(),
4,
'Unexpected number of requests made'
'Unexpected number of requests made. Run testUtils.getAPIHistoryDebug() to see the requests'
);
return;
});
Expand Down Expand Up @@ -85,9 +85,9 @@ describe('transactionalSMS', () => {
);
// check number of API calls
assert.equal(
Object.values(testUtils.getAPIHistory()).flat().length,
testUtils.getAPIHistoryLength(),
5,
'Unexpected number of requests made'
'Unexpected number of requests made. Run testUtils.getAPIHistoryDebug() to see the requests'
);
return;
});
Expand Down Expand Up @@ -139,9 +139,9 @@ describe('transactionalSMS', () => {
file(testUtils.getExpectedFile('9999999', 'transactionalSMS', 'build', 'amp'))
);
assert.equal(
Object.values(testUtils.getAPIHistory()).flat().length,
testUtils.getAPIHistoryLength(),
4,
'Unexpected number of requests made'
'Unexpected number of requests made. Run testUtils.getAPIHistoryDebug() to see the requests'
);
return;
});
Expand Down
24 changes: 24 additions & 0 deletions test/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,12 +138,36 @@ exports.mockReset = () => {
fsmock.restore();
apimock.restore();
};
/**
* helper to return amount of api callouts
*
* @param {boolean} [includeToken] if true, will include token calls in count
* @returns {object} of API history
*/
exports.getAPIHistoryLength = (includeToken) => {
const historyArr = Object.values(apimock.history).flat();
if (includeToken) {
return historyArr.length;
}
return historyArr.filter((item) => item.url !== '/v2/token').length;
};
/**
* helper to return api history
*
* @returns {object} of API history
*/
exports.getAPIHistory = () => apimock.history;
/**
* helper to return most important fields for each api call
*
* @returns {object} of API history
*/
exports.getAPIHistoryDebug = () => {
const historyArr = Object.values(apimock.history)
.flat()
.map((item) => ({ url: item.url, data: item.data }));
return historyArr;
};

/**
* escapes string for regex
Expand Down

0 comments on commit 0009c13

Please sign in to comment.