1.1.0 • Published 6 months ago

@janiscommerce/model-test v1.1.0

Weekly downloads
-
License
ISC
Repository
github
Last release
6 months ago

model-test

Build Status Coverage Status npm version

A helper package to test Janis Model created with @janiscommerce/model.

:hammer: Usage

You must add a ./tests/model-test.js file like the following.

'use strict';

const modelTest = require('@janiscommerce/model-test');

modelTest();

Models

The package will look for the models of a service located in the ./{process.env.MS_PATH}/models/ folder.

Exclude models from testing

You can exclude specific model files from being tested by passing an exclude array to the test function.

const modelTest = require('@janiscommerce/model-test');

modelTest({
	exclude: ['model-to-skip', 'another-model']
});

Each item in the array should be the filename of the model you want to skip — do not include the .js extension.

📝 The names are matched against the model filenames located in your models folder. Matching is case-sensitive.

Validations

The package automatically will validate each model according @janiscommerce/model.

The validations performed by the package are as follows

Table/Collection

The table/collection is validated using the static getter table. Should return a String value.

Database Key

The databaseKey is validated using the non-static getter databaseKey. Should return a String value.

Statuses

The statuses are validated using the static getter statuses. Should return an Object with keys and values as Strings.

Fields

The fields are validated using the static getter fields. Should return an Object with keys and values as Strings.

The validation is performed with a struct.

'use strict';

const { struct } = require('superstruct');

module.exports = struct.partial({
	field: 'string?',
	type: 'string?'
});

Indexes

The indexes are validated using the static getter indexes. Should return an Object with keys and values as Strings.

The validation is performed with a struct.

'use strict';

const { struct } = require('superstruct');

module.exports = struct.partial({
	name: 'string',
	key: 'object',
	unique: 'boolean?',
	expireAfterSeconds: 'number?',
	partialFilterExpression: 'object?',
	sparse: 'boolean?'
});

For more information see @janiscommerce/mongodb-index-creator.

Log Creation

The automatic Log Creation is validated using the static getter shouldCreateLogs. Should return a Boolean.

For more information see @janiscommerce/log.

Excluding fields from logs

The validation is performed using the static getter excludeFieldsInLog. Should return a String Array.

For more information see @janiscommerce/log.