diff --git a/lib/formatters/formatter.ts b/lib/formatters/formatter.ts index 5310ec19..d0ca6dca 100644 --- a/lib/formatters/formatter.ts +++ b/lib/formatters/formatter.ts @@ -14,7 +14,7 @@ export abstract class Formatter { integrateFastaHeaders(data: { [key: string]: string }[], fastaMapper: { [key: string]: string }): object[] { const key = Object.keys(data[0])[0]; data.forEach((entry, i) => { - data[i] = Object.assign({ fastaHeader: fastaMapper[entry[key]] }, entry); + data[i] = Object.assign({ fasta_header: fastaMapper[entry[key]] }, entry); }); return data; } diff --git a/tests/formatters/csv_formatter.test.ts b/tests/formatters/csv_formatter.test.ts index 2b9a3b85..2ea80c37 100644 --- a/tests/formatters/csv_formatter.test.ts +++ b/tests/formatters/csv_formatter.test.ts @@ -23,8 +23,8 @@ test('test convert', () => { }); test('test format with fasta', () => { - //const fasta = [['>test', '5']]; - //const object = [TestObject.testObject(), TestObject.testObject()]; - //const csv = [`>test,${TestObject.asCsv()}`, TestObject.asCsv(), ""].join("\n"); - //expect(formatter.format(object, fasta, false)).toBe(csv); + const fasta = { 5: ">test" }; + const object = [TestObject.testObject(), TestObject.testObject()]; + const csv = [`>test,${TestObject.asCsv()}`, `>test,${TestObject.asCsv()}`, ""].join("\n"); + expect(formatter.format(object, fasta, false)).toBe(csv); }); diff --git a/tests/formatters/formatter.test.ts b/tests/formatters/formatter.test.ts new file mode 100644 index 00000000..c041f31b --- /dev/null +++ b/tests/formatters/formatter.test.ts @@ -0,0 +1,12 @@ +import { FormatterFactory } from "../../lib/formatters/formatter_factory"; +import { TestObject } from "./test_object"; + +test('test integrate fasta headers', async () => { + const formatter = FormatterFactory.getFormatter("csv"); + const fasta = { 5: ">test" }; + const object = [TestObject.testObject(), TestObject.testObject()]; + const integrated = [Object.assign({ fasta_header: ">test" }, TestObject.testObject()), Object.assign({ fasta_header: ">test" }, TestObject.testObject())]; + // eslint-disable-next-line @typescript-eslint/ban-ts-comment + // @ts-ignore + expect(formatter.integrateFastaHeaders(object, fasta)).toEqual(integrated); +}); diff --git a/tests/formatters/json_formatter.test.ts b/tests/formatters/json_formatter.test.ts index c4e80648..42e14293 100644 --- a/tests/formatters/json_formatter.test.ts +++ b/tests/formatters/json_formatter.test.ts @@ -21,8 +21,8 @@ test('test convert', () => { }); test('test format with fasta', () => { - //const fasta = [['>test', '5']]; - //const object = [TestObject.testObject()]; - //const json = '{"fasta_header":">test","integer":5,"string":"string","list":["a",2,false]}'; - //expect(formatter.format(object, fasta, true)).toBe(json); + const fasta = { 5: ">test" }; + const object = [TestObject.testObject()]; + const json = '{"fasta_header":">test","integer":5,"string":"string","list":["a",2,false]}'; + expect(formatter.format(object, fasta, true)).toBe(json); }); diff --git a/tests/formatters/xml_formatter.test.ts b/tests/formatters/xml_formatter.test.ts index c327d034..6994861b 100644 --- a/tests/formatters/xml_formatter.test.ts +++ b/tests/formatters/xml_formatter.test.ts @@ -21,8 +21,8 @@ test('test convert', () => { }); test('test format with fasta', () => { - //const fasta = [['>test', '5']]; - //const object = [TestObject.testObject()]; - //const json = '{"fasta_header":">test","integer":5,"string":"string","list":["a",2,false]}'; - //expect(formatter.format(object, fasta, true)).toBe(json); + const fasta = { 5: ">test" }; + const object = [TestObject.testObject()]; + const xml = `>test${TestObject.asXml()}`; + expect(formatter.format(object, fasta, true)).toBe(xml); });