Skip to content

Commit

Permalink
Update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Sparticuz committed Aug 6, 2021
1 parent 063f26b commit 5ee9d85
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 35 deletions.
13 changes: 7 additions & 6 deletions test/convert-field-json-to-fdf.js
Original file line number Diff line number Diff line change
@@ -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",
Expand All @@ -13,7 +14,7 @@ test("Should generate an corresponding FDF object", (t) => {
nascar: "Off",
};

const data2 = [
const input = [
{
fieldType: "Text",
fieldValue: "John",
Expand Down Expand Up @@ -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);
});
26 changes: 12 additions & 14 deletions test/fdf.js
Original file line number Diff line number Diff line change
@@ -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);
});
8 changes: 4 additions & 4 deletions test/generate-fdf-template.js
Original file line number Diff line number Diff line change
@@ -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: "",
Expand All @@ -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);
});
19 changes: 13 additions & 6 deletions test/generate-field-json.js
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -28,29 +29,35 @@ 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,
first_name: "मुख्यपृष्ठम्",
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: "",
Expand Down Expand Up @@ -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);
});
Expand Down
10 changes: 5 additions & 5 deletions test/map-form-to-pdf.js
Original file line number Diff line number Diff line change
@@ -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 = {
Expand All @@ -13,7 +13,7 @@ test("Should convert formJson to FDF data as expected", (t) => {
nascarField: "nascar",
};

const data3 = [
const data = [
{
fieldType: "Text",
fieldValue: "John",
Expand Down Expand Up @@ -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",
Expand All @@ -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);
});

0 comments on commit 5ee9d85

Please sign in to comment.