Add test for label parsing

This commit is contained in:
Jackson Harper
2023-05-24 18:17:29 +08:00
parent 9218e16415
commit c64476b44a
2 changed files with 29 additions and 0 deletions

View File

@ -109,3 +109,29 @@ describe('A file with no status set', () => {
expect(states).to.eql([undefined, ArticleSavingRequestStatus.Archived])
})
})
describe('A file with some labels', () => {
it('gets the labels, handles empty, and trims extra whitespace', async () => {
const importedLabels: (string[] | undefined)[] = []
const stream = fs.createReadStream('./test/csv/data/labels.csv')
const stub = stubImportCtx()
stub.urlHandler = (
ctx: ImportContext,
url,
state?: ArticleSavingRequestStatus,
labels?: string[]
): Promise<void> => {
importedLabels.push(labels)
return Promise.resolve()
}
await importCsv(stub, stream)
expect(stub.countFailed).to.equal(0)
expect(stub.countImported).to.equal(3)
expect(importedLabels).to.eql([
['Label1', 'Label2', 'Label 3', 'Label 4'],
[],
[],
])
})
})

View File

@ -0,0 +1,3 @@
"https://test.url/path01",,"[Label1,Label2, Label 3, Label 4 ]"
"https://test.url/path02",,"[]"
"https://test.url/path03",,
1 https://test.url/path01 [Label1,Label2, Label 3, Label 4 ]
2 https://test.url/path02 []
3 https://test.url/path03