Skip to content

Commit

Permalink
test: acceptance test the public api
Browse files Browse the repository at this point in the history
  • Loading branch information
acodeninja committed Jul 30, 2024
1 parent 41e423a commit 3a0f63e
Show file tree
Hide file tree
Showing 7 changed files with 63 additions and 5 deletions.
7 changes: 6 additions & 1 deletion ava.config.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
export default {
files: ['!test/**/*'],
files: [
'!test/**/*',
'src/**/*.test.js',
'exports/**/*.test.js',
'test/acceptance/**/*.test.js',
],
};
2 changes: 1 addition & 1 deletion exports/engine/file.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
import FileEngine from '../../src/engines/FileEngine.js';
import FileEngine from '../../src/engine/FileEngine.js';

export default FileEngine;
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
},
"exports": {
".": "./exports/default.js",
"./store/*": "./exports/store/*.js"
"./engine/*": "./exports/engine/*.js"
},
"dependencies": {
"ajv": "^8.16.0",
Expand Down
2 changes: 1 addition & 1 deletion src/Persist.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export default class Persist {
* @static
* @param {string} group - Name of the group containing the engine
* @param {Engine} engine - The engine class you wish to configure and add to the group
* @param {map?} configuration - The configuration to use with the engine
* @param {object?} configuration - The configuration to use with the engine
*/
static addEngine(group, engine, configuration) {
if (!this._engine[group]) this._engine[group] = {};
Expand Down
3 changes: 2 additions & 1 deletion src/type/Model.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import SchemaCompiler from '../SchemaCompiler.js';
import StringType from './simple/StringType.js';
import {monotonicFactory} from 'ulid';

const createID = monotonicFactory();

export default class Model {
static id = String.required;
static id = StringType.required;
static _required = false;

constructor(data = {}) {
Expand Down
26 changes: 26 additions & 0 deletions test/acceptance/Persist.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import Persist from '@acodeninja/persist';
import test from 'ava';

test('Persist contains the String Type', t => {
t.is(Persist.Type.String.name, 'StringType');
});

test('Persist contains the Number Type', t => {
t.is(Persist.Type.Number.name, 'NumberType');
});

test('Persist contains the Boolean Type', t => {
t.is(Persist.Type.Boolean.name, 'BooleanType');
});

test('Persist contains the Resolved Slug Type', t => {
t.is(Persist.Type.Resolved.Slug.name, 'SlugType');
});

test('Persist contains the Complex Custom Type', t => {
t.is(Persist.Type.Custom.name, 'CustomType');
});

test('Persist contains the Model Type', t => {
t.is(Persist.Type.Model.name, 'Model');
});
26 changes: 26 additions & 0 deletions test/acceptance/engines/FileEngine.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import FileEngine from '@acodeninja/persist/engine/file';
import Persist from '@acodeninja/persist';
import fs from 'node:fs/promises';
import test from 'ava';

test('Persist allows adding the FileEngine', t => {
Persist.addEngine('files', FileEngine, {
path: '/tmp/fileEngine',
});

t.like(Persist._engine.files.FileEngine._configuration, {
path: '/tmp/fileEngine',
filesystem: fs,
});
});

test('Persist allows retrieving a FileEngine', t => {
Persist.addEngine('files', FileEngine, {
path: '/tmp/fileEngine',
});

t.like(Persist.getEngine('files', FileEngine)._configuration, {
path: '/tmp/fileEngine',
filesystem: fs,
});
});

0 comments on commit 3a0f63e

Please sign in to comment.