Skip to content

Commit

Permalink
Merge pull request #952 from Accenture/task/951-new-user-documentatio…
Browse files Browse the repository at this point in the history
…n-test-fails-due-to-calculated-days-since-last-login

#951: fix test for user-documentation
  • Loading branch information
JoernBerkefeld committed Jun 1, 2023
2 parents 537707f + b742739 commit f3d3f78
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions test/type.user.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const file = chaiFiles.file;
const cache = require('../lib/util/cache');
const testUtils = require('./utils');
const handler = require('../lib/index');
const File = require('../lib/util/file');

describe('type: user', () => {
beforeEach(() => {
Expand Down Expand Up @@ -35,9 +36,22 @@ 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'))
);
// ! this test needs to update the lastLoginDate counter because it changes with every passing day
const expectedFile = await File.readFile(
testUtils.getExpectedFile('1111111', 'user', 'retrieve', 'md'),
{ encoding: 'utf8' }
);
const regexFindDaysSinceLogin =
/\| (\d*) (seconds|minutes|days|weeks|months|years){1} \|/gm;
// fetch expected time since last login
const expectedDaysSinceLogin = expectedFile.match(regexFindDaysSinceLogin);
// load actual file and replace days since last login with expected value
const actualFile = (
await File.readFile(`./docs/user/testInstance.users.md`, {
encoding: 'utf8',
})
).replaceAll(regexFindDaysSinceLogin, expectedDaysSinceLogin);
expect(actualFile).to.equal(expectedFile);

assert.equal(
testUtils.getAPIHistoryLength(),
Expand Down

0 comments on commit f3d3f78

Please sign in to comment.