Skip to content

Commit

Permalink
add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
bmesuere committed Aug 5, 2024
1 parent 2435f1f commit b21872d
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 13 deletions.
2 changes: 1 addition & 1 deletion lib/formatters/formatter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
8 changes: 4 additions & 4 deletions tests/formatters/csv_formatter.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
12 changes: 12 additions & 0 deletions tests/formatters/formatter.test.ts
Original file line number Diff line number Diff line change
@@ -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);
});
8 changes: 4 additions & 4 deletions tests/formatters/json_formatter.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
8 changes: 4 additions & 4 deletions tests/formatters/xml_formatter.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = `<result><fasta_header>&gt;test</fasta_header>${TestObject.asXml()}</result>`;
expect(formatter.format(object, fasta, true)).toBe(xml);
});

0 comments on commit b21872d

Please sign in to comment.