Skip to content

Commit

Permalink
#800: add tests for when document is run (user, dataExtension)
Browse files Browse the repository at this point in the history
  • Loading branch information
JoernBerkefeld committed May 30, 2023
1 parent 7e0b929 commit 1f3e0d3
Show file tree
Hide file tree
Showing 5 changed files with 89 additions and 2 deletions.
19 changes: 19 additions & 0 deletions test/resources/1111111/user/retrieve-expected.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# User Overview - testInstance

## Users (1)

| Name | Last successful Login | Active | Access Locked out | API User | Must change PW | Default BU | BU Access | Roles | Login | ID | Key | E-Mail | Notification E-Mail | Timezone | SFMC Locale | Modified Date | Modified By | Created Date |
| --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- |
| user test | 96 days || - | - | - | <nobr>_ParentBU_ (1111111)</nobr> | <nobr>_ParentBU_ (1111111)</nobr>,<br> <nobr>testBU (9999999)</nobr> | <nobr>Administrator,</nobr><br> <nobr>Content Creator,</nobr><br> <nobr>Marketing Cloud Administrator</nobr> | user_test@accenture.asgr | 700301950 | testExisting_user | user_test@accenture.com | user_test@accenture.com | GMT+01:00 | en-GB | 2022-06-21 01:43:02.64 | 123456 | 2019-09-06 01:59:07.097 |


## Inactivated Users (0)

| Name | Last successful Login | Active | Access Locked out | API User | Must change PW | Default BU | BU Access | Roles | Login | ID | Key | E-Mail | Notification E-Mail | Timezone | SFMC Locale | Modified Date | Modified By | Created Date |
| --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- |


## Installed Packages (0)

| Name | Last successful Login | Active | Access Locked out | API User | Must change PW | Default BU | BU Access | Roles | Login | ID | Key | E-Mail | Notification E-Mail | Timezone | SFMC Locale | Modified Date | Modified By | Created Date |
| --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- |
18 changes: 18 additions & 0 deletions test/resources/9999999/dataExtension/retrieve-expected.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
## testExisting_dataExtension

**Description:** bla bla

**Folder:** Data Extensions/

**Fields in table:** 4

**Sendable:** Yes (`ContactKey` to `Subscriber Key`)

**Testable:** Yes

| Name | FieldType | MaxLength | IsPrimaryKey | IsNullable | DefaultValue |
| --- | --- | --- | --- | --- | --- |
| FirstName | Text | 50 | - | + | |
| LastName | Text | 50 | - | + | |
| EmailAddress | EmailAddress | 254 | - | - | |
| ContactKey | Text | 50 | + | - | |
13 changes: 12 additions & 1 deletion test/type.dataExtension.test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
const assert = require('chai').assert;
const chai = require('chai');
const chaiFiles = require('chai-files');
const assert = chai.assert;
const expect = chai.expect;
const file = chaiFiles.file;
const cache = require('../lib/util/cache');
const testUtils = require('./utils');
const handler = require('../lib/index');
Expand Down Expand Up @@ -29,6 +33,13 @@ describe('type: dataExtension', () => {

'returned metadata was not equal expected'
);
// check if MD file was created and equals expectations
expect(
file(testUtils.getActualDoc('testExisting_dataExtension', 'dataExtension'))
).to.equal(
file(testUtils.getExpectedFile('9999999', 'dataExtension', 'retrieve', 'md'))
);

assert.equal(
testUtils.getAPIHistoryLength(),
5,
Expand Down
31 changes: 30 additions & 1 deletion test/type.user.test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
const assert = require('chai').assert;
const chai = require('chai');
const chaiFiles = require('chai-files');
const assert = chai.assert;
chai.use(chaiFiles);
const expect = chai.expect;
const file = chaiFiles.file;
const cache = require('../lib/util/cache');
const testUtils = require('./utils');
const handler = require('../lib/index');
Expand Down Expand Up @@ -29,13 +34,34 @@ describe('type: user', () => {

'returned metadata was not equal expected'
);
// check if MD file was created and equals expectations
expect(file(`./docs/user/testInstance.users.md`)).to.equal(
file(testUtils.getExpectedFile('1111111', 'user', 'retrieve', 'md'))
);

assert.equal(
testUtils.getAPIHistoryLength(),
6,
'Unexpected number of requests made. Run testUtils.logAPIHistoryDebug() to see the requests'
);
return;
});
it('Should retrieve a specific user but not run document', async () => {
// WHEN
await handler.retrieve('testInstance/_ParentBU_', ['user'], ['testExisting_user']);
// THEN
assert.equal(process.exitCode, false, 'retrieve should not have thrown an error');

// because user is single-document-type we would not want to find an md file when we retrieve specific keys. only the generic retrieve updates it
expect(file(`./docs/user/testInstance.users.md`)).to.not.exist;

assert.equal(
testUtils.getAPIHistoryLength(),
4,
'Unexpected number of requests made. Run testUtils.logAPIHistoryDebug() to see the requests'
);
return;
});
});
describe('Deploy ================', () => {
beforeEach(() => {
Expand Down Expand Up @@ -74,6 +100,9 @@ describe('type: user', () => {
await testUtils.getExpectedJson('1111111', 'user', 'update'),
'returned metadata was not equal expected for update'
);
// because user is single-document-type we would not want to find an md file getting created by deploy. only retrieve updates it
expect(file(`./docs/user/testInstance.users.md`)).to.not.exist;

assert.equal(
testUtils.getAPIHistoryLength(),
9,
Expand Down
10 changes: 10 additions & 0 deletions test/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,16 @@ const resourceFactory = require('./resourceFactory');
*/
exports.getActualJson = (customerKey, type, buName = 'testBU') =>
File.readJSON(`./retrieve/testInstance/${buName}/${type}/${customerKey}.${type}-meta.json`);
/**
* gets file from Retrieve folder
*
* @param {string} customerKey of metadata
* @param {string} type of metadata
* @param {string} [buName] used when we need to test on ParentBU
* @returns {Promise.<string>} file in string form
*/
exports.getActualDoc = (customerKey, type, buName = 'testBU') =>
`./retrieve/testInstance/${buName}/${type}/${customerKey}.${type}-doc.md`;
/**
* gets file from Retrieve folder
*
Expand Down

0 comments on commit 1f3e0d3

Please sign in to comment.