-
-
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.
- Loading branch information
Showing
5 changed files
with
74 additions
and
7 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
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 |
---|---|---|
@@ -1,2 +1,2 @@ | ||
import CSVFormatter from './CSVFormatter'; | ||
import CSVFormatter from './Format'; | ||
export default CSVFormatter; |
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 |
---|---|---|
@@ -1,8 +1,39 @@ | ||
import { assert } from 'chai'; | ||
import logger from '../entry'; | ||
import { verifyStdout } from '../utils'; | ||
import CSV from '../entry'; | ||
import { testFormatter } from '../utils'; | ||
import Factory from '../Test'; | ||
|
||
const factory = new Factory(); | ||
|
||
suite('Configurations'); | ||
|
||
test('Default configuration', function () { | ||
before(async () => { | ||
await factory.cleanTmpFolder(); | ||
await factory.setTmpFolder(); | ||
}); | ||
|
||
test('Positive: default configuration', async function () { | ||
const formatter = CSV([ 'user', 'action' ]); | ||
const data = [ | ||
{ user: 'e3c0b365-26fd-54fc-afd7-d844c1d47a95', action: 'CREATE_POST' }, | ||
{ user: '', action: 'UPDATE_POST' }, | ||
{ user: 'e3c0b365-26fd-54fc-afd7-d844c1d47a95' }, | ||
{ }, | ||
{ user: 'e3c0b365-26fd-54fc-afd7-d844c1d47a95', time: '2019-08-06T11:46:46.434Z' }, | ||
{ action: 'DELETE_POST', user: 'e595b156-f526-5b94-ab76-c9fb610e286b' } | ||
]; | ||
|
||
const expected = `e3c0b365-26fd-54fc-afd7-d844c1d47a95;CREATE_POST | ||
;UPDATE_POST | ||
e3c0b365-26fd-54fc-afd7-d844c1d47a95; | ||
; | ||
e3c0b365-26fd-54fc-afd7-d844c1d47a95; | ||
e595b156-f526-5b94-ab76-c9fb610e286b;DELETE_POST | ||
`; | ||
|
||
await testFormatter(formatter, data, expected); | ||
}); | ||
|
||
|
||
after(async () => { | ||
await factory.cleanTmpFolder(); | ||
}); |
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,33 @@ | ||
import path from 'path'; | ||
import uuid from 'uuid'; | ||
import fse from 'fs-extra'; | ||
import { assert } from 'chai'; | ||
import { createLogger, transports } from 'winston'; | ||
import { tmpFolder } from './constants'; | ||
|
||
export const pause = time => new Promise(resolve => setTimeout(resolve, time)); | ||
|
||
export async function testFormatter(formatter, data, expected) { | ||
const fileId = uuid.v4(); | ||
const filePath = path.join(tmpFolder, `formatter-${fileId}.csv`); | ||
const logger = createLogger({ | ||
level : 'info', | ||
format : formatter, | ||
transports : [ | ||
new transports.Console(), | ||
new transports.File({ | ||
filename : filePath | ||
}) | ||
] | ||
}); | ||
|
||
data.forEach(item => { | ||
logger.log('info', item); | ||
}); | ||
|
||
await pause(1000); | ||
|
||
const content = await fse.readFile(filePath); | ||
|
||
assert.equal(content.toString(), expected); | ||
} |