|
| 1 | +import * as url from 'node:url'; |
| 2 | + |
| 3 | +import sinon from 'sinon'; |
| 4 | + |
| 5 | +import { ImportUserLAstLogeedAtScript } from '../../../../src/identity-access-management/scripts/import-user-last-logged-at.script.js'; |
| 6 | +import { expect } from '../../../test-helper.js'; |
| 7 | + |
| 8 | +const currentDirectory = url.fileURLToPath(new URL('.', import.meta.url)); |
| 9 | + |
| 10 | +describe('ImportUserLAstLogeedAtScript', function () { |
| 11 | + describe('Options', function () { |
| 12 | + it('parses CSV file correctly', async function () { |
| 13 | + // given |
| 14 | + const testCsvFile = `${currentDirectory}files/new-update-last-logged-at.csv`; |
| 15 | + const script = new ImportUserLAstLogeedAtScript(); |
| 16 | + |
| 17 | + // when |
| 18 | + const { options } = script.metaInfo; |
| 19 | + const fileData = await options.file.coerce(testCsvFile); |
| 20 | + |
| 21 | + // then |
| 22 | + expect(fileData).to.deep.equal([ |
| 23 | + { userId: 1234, last_activity: new Date('2017-09-05T14:00:08Z') }, |
| 24 | + { userId: 4567, last_activity: new Date('2018-03-02T15:26:16Z') }, |
| 25 | + ]); |
| 26 | + }); |
| 27 | + }); |
| 28 | + |
| 29 | + describe('#handle', function () { |
| 30 | + let script; |
| 31 | + let importUserLastLoggedAt; |
| 32 | + |
| 33 | + beforeEach(function () { |
| 34 | + script = new ImportUserLAstLogeedAtScript(); |
| 35 | + importUserLastLoggedAt = sinon.stub(); |
| 36 | + }); |
| 37 | + |
| 38 | + it('runs the script', async function () { |
| 39 | + // given |
| 40 | + const file = [ |
| 41 | + { userId: 1234, last_activity: '2017-09-05 14:00:08+0000' }, |
| 42 | + { userId: 4567, last_activity: '2018-03-02 15:26:16+0000' }, |
| 43 | + ]; |
| 44 | + |
| 45 | + // when |
| 46 | + await script.handle({ options: { file }, importUserLastLoggedAt }); |
| 47 | + |
| 48 | + // then |
| 49 | + expect(importUserLastLoggedAt).to.have.been.calledWith({ |
| 50 | + userId: 1234, |
| 51 | + lastActivity: '2017-09-05 14:00:08+0000', |
| 52 | + }); |
| 53 | + expect(importUserLastLoggedAt).to.have.been.calledWith({ |
| 54 | + userId: 4567, |
| 55 | + lastActivity: '2018-03-02 15:26:16+0000', |
| 56 | + }); |
| 57 | + }); |
| 58 | + }); |
| 59 | +}); |
0 commit comments