Skip to main content
Version: latest

Testing

Testing is a way to maintain reliability of your Flatfile integrations as it evolves.

Highlights:

Environments

Flatfile provides a developer mode and production environment.

Developer mode is an easy way to get up and running without securing user imports. Useful during an initial integration of a Portal into your own application.

Deploying to developer mode (test) or production (prod) is based on the variable set in the .env file with the Platform SDK.

Production:

FLATFILE_ENV=prod

Developer mode:

FLATFILE_ENV=test

See example:

.env.example
# An access and a secret key are required to use the Flatfile API
FLATFILE_ACCESS_KEY_ID=
FLATFILE_SECRET=

# Add your targetted env here, it defaults to `test`. Switch to `prod` when ready
FLATFILE_ENV=prod

# The team ID associated with the schema thats being deployed
FLATFILE_TEAM_ID=

# Optional - if it is not set this will default to https://api.us.flatfile.io
FLATFILE_API_URL=

Testing in code

Run tests on your Workbook as you make changes.

This is a fast way to ensure you don't accidentally break the upload behavior.

The Platform SDK starter (installed with npx flatfile init) includes a utility to help test sheets.

You can run a test on a Workbook by adding a .spec.ts file and importing your workbook file.

To run the test use the command line

npm run test

Example Workbook with a test file:

my-workbook.spec.ts
import { MyWorkbook } from "./MyWorkbook";

describe("Workbook tests ->", () => {
const testSheet = new SheetTester(TestWorkbook, "TestSheet");

test("Single Record works", async () => {
const inputRow = { firstName: "foo", age: "10", testBoolean: "true" };
const expectedOutputRow = { age: 20, firstName: "FOO", testBoolean: true };
const res = await testSheet.testRecord(inputRow);
expect(res).toMatchObject(expectedOutputRow);
});

test("Multiple Records work", async () => {
const inputRows = [
{ firstName: "foo", age: "10", testBoolean: "true" },
{ firstName: "bar", age: "8", testBoolean: "true" },
];

const expectedOutputRows = [
{ age: 20, firstName: "FOO", testBoolean: true },
{ age: 16, firstName: "BAR", testBoolean: true },
];

const results = await testSheet.testRecords(inputRows);
expect(results).toMatchObject(expectedOutputRows);
});

test("transformField() work", async () => {
expect(await testSheet.transformField("firstName", "alex")).toEqual("ALEX");
expect(await testSheet.transformField("age", "10")).toEqual(20);
expect(await testSheet.transformField("testBoolean", "true")).toEqual(true);
});
});