From 5ee9d856f4ba15ed86ddfd889e7a897f8b7884ef Mon Sep 17 00:00:00 2001 From: Sparticuz Date: Fri, 6 Aug 2021 11:14:36 -0400 Subject: [PATCH] Update tests --- test/convert-field-json-to-fdf.js | 13 +++++++------ test/fdf.js | 26 ++++++++++++-------------- test/generate-fdf-template.js | 8 ++++---- test/generate-field-json.js | 19 +++++++++++++------ test/map-form-to-pdf.js | 10 +++++----- 5 files changed, 41 insertions(+), 35 deletions(-) diff --git a/test/convert-field-json-to-fdf.js b/test/convert-field-json-to-fdf.js index 9c94b93..09cf889 100644 --- a/test/convert-field-json-to-fdf.js +++ b/test/convert-field-json-to-fdf.js @@ -1,8 +1,9 @@ const test = require("ava"); -const { convFieldJson2FDF } = require(".."); +const convertFieldJsonToFDF = + require("../dist/convert-field-json-to-fdf").default; -test("Should generate an corresponding FDF object", (t) => { - const expected4 = { +test("Should change the boolean to a 'Yes/Off'", (t) => { + const expected = { baseball: "Yes", basketball: "Off", date: "Jan 1, 2013", @@ -13,7 +14,7 @@ test("Should generate an corresponding FDF object", (t) => { nascar: "Off", }; - const data2 = [ + const input = [ { fieldType: "Text", fieldValue: "John", @@ -56,6 +57,6 @@ test("Should generate an corresponding FDF object", (t) => { }, ]; - const FDFData = convFieldJson2FDF(data2); - t.deepEqual(FDFData, expected4); + const results = convertFieldJsonToFDF(input); + t.deepEqual(results, expected); }); diff --git a/test/fdf.js b/test/fdf.js index 599bc9d..8f78b53 100644 --- a/test/fdf.js +++ b/test/fdf.js @@ -1,21 +1,19 @@ const test = require("ava"); const createFdf = require("../dist/fdf").default; -const data = { - baseball: "Yes", - basketball: "Off", - date: "Jan 1, 2013", - first_name: "1) John", - football: "Off", - hockey: "Yes", - last_name: "Doe", - nascar: "Off", -}; - -test("should create a FDF template with a null value", (t) => { +test("should create a FDF template and not error with a null value", (t) => { const fdfData = createFdf({ - ...data, - nulval: undefined, + baseball: "Yes", + basketball: "Off", + date: "Jan 1, 2013", + first_name: "1) John", + football: "Off", + hockey: "Yes", + last_name: "Doe", + nascar: "Off", + // eslint-disable-next-line unicorn/no-null + nulval: null, + udfval: undefined, }); t.assert(fdfData); }); diff --git a/test/generate-fdf-template.js b/test/generate-fdf-template.js index 730683d..37b0cf5 100644 --- a/test/generate-fdf-template.js +++ b/test/generate-fdf-template.js @@ -1,12 +1,12 @@ const test = require("ava"); const { fdfTemplate } = require("./_expected-data"); -const { generateFDFTemplate } = require(".."); +const generateFDFTemplate = require("../dist/generate-fdf-template").default; const sourcePDF = "test/test.pdf"; const source2PDF = "test/test1.pdf"; test("should generate a FDF Template as expected", async (t) => { - const expected3 = { + const expected = { baseball: "", basketball: "", date: "", @@ -17,10 +17,10 @@ test("should generate a FDF Template as expected", async (t) => { nascar: "", }; const fdf = await generateFDFTemplate(sourcePDF); - t.deepEqual(fdf, expected3); + t.deepEqual(fdf, expected); }); -test("should generate another FDF Template with no errors", async (t) => { +test("should generate a large FDF Template with no errors", async (t) => { const fdf = await generateFDFTemplate(source2PDF); t.deepEqual(fdf, fdfTemplate); }); diff --git a/test/generate-field-json.js b/test/generate-field-json.js index ba2d140..6f955eb 100644 --- a/test/generate-field-json.js +++ b/test/generate-field-json.js @@ -5,6 +5,7 @@ const { formFields } = require("./_expected-data"); const sourcePDF = "test/test.pdf"; const source2PDF = "test/test1.pdf"; +const source3PDF = "test/test_partial.pdf"; const destination2PDF = "test/test_complete2.pdf"; const destination3PDF = "test/test_complete3.pdf"; @@ -28,15 +29,19 @@ test("should use toFile to create a completely filled PDF that is read-only", as }); test("should create an unflattened PDF with unfilled fields remaining", async (t) => { - const data2 = { + const filledData = { first_name: "Jerry", }; - await fillForm(sourcePDF, data2, false).toFile(destination3PDF); + await fillForm(sourcePDF, filledData, false).toFile(destination3PDF); const rwFdf = await generateFieldJson(destination3PDF); t.not(rwFdf.length, 0); }); +/** + * This test is passing, but not actually saving the UTF-8 correctly. + * See #11 + */ test("should handle expanded utf characters and diacritics", async (t) => { const diacriticsData = { ...data, @@ -44,13 +49,15 @@ test("should handle expanded utf characters and diacritics", async (t) => { last_name: "العقائدية الأخرى", }; - await fillForm(sourcePDF, diacriticsData, false).toFile(destination4PDF); + await fillForm(source2PDF, diacriticsData, ["need_appearances"]).toFile( + destination4PDF + ); const fdf = await generateFieldJson(destination4PDF); t.not(fdf.length, 0); }); test("should generate form field JSON as expected", async (t) => { - const expected2 = [ + const expected = [ { fieldFlags: "0", fieldMaxLength: "", @@ -110,10 +117,10 @@ test("should generate form field JSON as expected", async (t) => { ]; const fdf = await generateFieldJson(sourcePDF); - t.deepEqual(fdf, expected2); + t.deepEqual(fdf, expected); }); -test("should generate another form field JSON with no errors", async (t) => { +test("should generate a large form field JSON with no errors", async (t) => { const fdf = await generateFieldJson(source2PDF); t.deepEqual(fdf, formFields); }); diff --git a/test/map-form-to-pdf.js b/test/map-form-to-pdf.js index ac6f323..33c447f 100644 --- a/test/map-form-to-pdf.js +++ b/test/map-form-to-pdf.js @@ -1,5 +1,5 @@ const test = require("ava"); -const { mapForm2PDF } = require(".."); +const mapForm2PDF = require("../dist/map-form-to-pdf").default; test("Should convert formJson to FDF data as expected", (t) => { const convMap = { @@ -13,7 +13,7 @@ test("Should convert formJson to FDF data as expected", (t) => { nascarField: "nascar", }; - const data3 = [ + const data = [ { fieldType: "Text", fieldValue: "John", @@ -56,7 +56,7 @@ test("Should convert formJson to FDF data as expected", (t) => { }, ]; - const expected5 = { + const expected = { baseball: "Yes", basketball: "Off", date: "Jan 1, 2013", @@ -66,6 +66,6 @@ test("Should convert formJson to FDF data as expected", (t) => { last_name: "John", nascar: "Off", }; - const convertedFDF = mapForm2PDF(data3, convMap); - t.deepEqual(convertedFDF, expected5); + const convertedFDF = mapForm2PDF(data, convMap); + t.deepEqual(convertedFDF, expected); });