Skip to content

Commit

Permalink
add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ETLaurent committed Apr 24, 2024
1 parent a98b3ee commit 93577f4
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 1 deletion.
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
"author": "Apostrophe Technologies",
"license": "UNLICENSED",
"devDependencies": {
"apostrophe": "github:apostrophecms/apostrophe",
"eslint": "^8.44.0",
"eslint-config-apostrophe": "^4.2.0",
"eslint-config-standard": "^17.1.0",
Expand Down
52 changes: 52 additions & 0 deletions test/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
const path = require('path');
const fs = require('fs');
const assert = require('assert').strict;
const xlsx = require('../lib/xlsx');

describe('@apostrophecms/import-export-xlsx', function () {
const filepath = path.join(__dirname, 'test.xlsx');

this.timeout(2000);

after(() => {
fs.unlinkSync(filepath);
});

describe('output', function () {
it('should write a .xlsx file with the docs and their properties stringified', async function () {
const docs = [
{
name: 'John Doe',
age: 42,
object: { foo: 'bar' },
array: [ 1, 2, { foo: 'bar' } ]
},
{
name: 'Jane Doe',
age: 43,
empty: ''
}
];
await xlsx.output(filepath, { docs });
});
});

describe('input', function () {
it('should read a .xlsx file and return the parsed docs in an object', async function () {
const result = await xlsx.input(filepath);
const expected = [
{
name: 'John Doe',
age: 42,
object: { foo: 'bar' },
array: [ 1, 2, { foo: 'bar' } ]
},
{
name: 'Jane Doe',
age: 43
}
];
assert.deepEqual(result.docs, expected);
});
});
});

0 comments on commit 93577f4

Please sign in to comment.