diff --git a/ava.config.js b/ava.config.js index 6d3ad4d..1b29b23 100644 --- a/ava.config.js +++ b/ava.config.js @@ -1,3 +1,8 @@ export default { - files: ['!test/**/*'], + files: [ + '!test/**/*', + 'src/**/*.test.js', + 'exports/**/*.test.js', + 'test/acceptance/**/*.test.js', + ], }; diff --git a/exports/engine/file.js b/exports/engine/file.js index 4b2306c..bbbb3f7 100644 --- a/exports/engine/file.js +++ b/exports/engine/file.js @@ -1,3 +1,3 @@ -import FileEngine from '../../src/engines/FileEngine.js'; +import FileEngine from '../../src/engine/FileEngine.js'; export default FileEngine; diff --git a/package.json b/package.json index 219c2c9..62eb058 100644 --- a/package.json +++ b/package.json @@ -13,7 +13,7 @@ }, "exports": { ".": "./exports/default.js", - "./store/*": "./exports/store/*.js" + "./engine/*": "./exports/engine/*.js" }, "dependencies": { "ajv": "^8.16.0", diff --git a/src/Persist.js b/src/Persist.js index c2d87ab..12476b3 100644 --- a/src/Persist.js +++ b/src/Persist.js @@ -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] = {}; diff --git a/src/type/Model.js b/src/type/Model.js index 124b0d8..e31eb88 100644 --- a/src/type/Model.js +++ b/src/type/Model.js @@ -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 = {}) { diff --git a/test/acceptance/Persist.test.js b/test/acceptance/Persist.test.js new file mode 100644 index 0000000..7fb2225 --- /dev/null +++ b/test/acceptance/Persist.test.js @@ -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'); +}); diff --git a/test/acceptance/engines/FileEngine.test.js b/test/acceptance/engines/FileEngine.test.js new file mode 100644 index 0000000..195ca97 --- /dev/null +++ b/test/acceptance/engines/FileEngine.test.js @@ -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, + }); +});