forked from HHS/Head-Start-TTADP
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
AR to csv: Simplify transformRelatedModel and begin tests
- Loading branch information
Showing
2 changed files
with
77 additions
and
62 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import { ActivityReport, User, sequelize } from '../models'; | ||
import activityReportToCsvRecord from './transform'; | ||
|
||
describe('activityReportToCsvRecord', () => { | ||
const mockAuthor = { | ||
id: 2099, | ||
name: 'Arthur', | ||
hsesUserId: '2099', | ||
hsesUsername: 'arthur.author', | ||
}; | ||
|
||
const mockReport = { | ||
id: 209914, | ||
regionId: 14, | ||
reason: 'Test CSV Export', | ||
status: 'approved', | ||
numberOfParticipants: 12, | ||
deliveryMethod: 'virtual', | ||
duration: 4.5, | ||
startDate: '2021-10-31', | ||
endSDate: '2021-11-31', | ||
ECLKCResourcesUsed: ['https://one.test', 'https://two.test'], | ||
nonECLKCResourcesUsed: ['one', 'two'], | ||
author: mockAuthor, | ||
lastUpdatedBy: mockAuthor, | ||
}; | ||
|
||
it('transforms arrays of strings into strings', async () => { | ||
const report = ActivityReport.build({ | ||
ECLKCResourcesUsed: ['https://one.test', 'https://two.test'], | ||
nonECLKCResourcesUsed: ['one', 'two'], | ||
}); | ||
const output = await activityReportToCsvRecord(report); | ||
const expectedOutput = { | ||
ECLKCResourcesUsed: 'https://one.test\nhttps://two.test', | ||
nonECLKCResourcesUsed: 'one\ntwo', | ||
}; | ||
expect(output).toMatchObject(expectedOutput); | ||
}); | ||
|
||
it('transforms related models into string values', async () => { | ||
const report = await ActivityReport.build(mockReport, { include: [{ model: User, as: 'author' }, { model: User, as: 'lastUpdatedBy' }] }); | ||
const output = await activityReportToCsvRecord(report); | ||
const { author: authorOutput, lastUpdatedBy: lastUpdatedByOutput } = output; | ||
expect(authorOutput).toEqual('Arthur'); | ||
expect(lastUpdatedByOutput).toEqual('Arthur'); | ||
}); | ||
}); |