aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjw2552018-04-14 18:26:38 +0100
committerjw2552018-04-14 18:26:38 +0100
commit5f687384dfeb807867c5d36bb83f672800599de6 (patch)
tree79640c2af975681f1f36047cb0eac6154081e7bc
parentfixed 1 test in auth.routes.test.ts (diff)
downloadmedicine-5f687384dfeb807867c5d36bb83f672800599de6.tar.gz
medicine-5f687384dfeb807867c5d36bb83f672800599de6.zip

confirmed matcher doesn’t like arrays

-rw-r--r--src/matcher/options.ts6
-rw-r--r--test/unit/options.unit.test.ts31
2 files changed, 32 insertions, 5 deletions
diff --git a/src/matcher/options.ts b/src/matcher/options.ts
index 9c78554..988d22b 100644
--- a/src/matcher/options.ts
+++ b/src/matcher/options.ts
@@ -83,14 +83,10 @@ export const array = (template: TemplateValue, values?: Value[]) => {
if (values === undefined) {
return array.bind(null, template);
}
- //console.trace()
- console.log(values)
const m: Checker = types.function(template)
? template
: match.bind(null, template);
- return values.every((item) => {
- return true;
- });
+ return values.every(m); //
};
// tslint:disable-next-line:typedef
diff --git a/test/unit/options.unit.test.ts b/test/unit/options.unit.test.ts
index a4c879a..4a85c2f 100644
--- a/test/unit/options.unit.test.ts
+++ b/test/unit/options.unit.test.ts
@@ -170,6 +170,7 @@ describe('Matching:', () => {
options.match(template)(matchee).should.be.true;
});
it('big bad unit test', () => {
+ /* tslint:disable:align */
const matchee = { status: 'success',
data: [ { privilege: 'admin', description: 'null', internal: false },
{ privilege: 'logging',
@@ -183,6 +184,36 @@ describe('Matching:', () => {
user_message: options.optional(types.string),
error_data: options.optional(types.anything)
};
+ /* tslint:enable:align */
+
+ options.match(template)(matchee).should.be.true;
+ });
+ it('bigger badder unit test', () => {
+ /* tslint:disable:align */
+ const matchee = [ { project_name: 'mocky',
+ users: [{ username: 'uname', access_level: 'admin'}],
+ public_metadata: { creation_date: '2018-04-14T17:13:44.291Z' },
+ private_metadata: {},
+ admin_metadata: {} } ];
+ const template = types.array({
+ project_name: types.string,
+ users: types.array({
+ username: types.string,
+ access_level: types.string
+ }),
+ public_metadata: types.anything,
+ private_metadata: options.optional(types.anything),
+ admin_metadata: options.optional(types.anything)
+ });
+ /* tslint:enable:align */
+
+ options.match(template)(matchee).should.be.true;
+ });
+ it('$$ Buy now: unit tests cheap and chearful. only £9.99', () => {
+ /* tslint:disable:align */
+ const matchee: any = [ 'test' ];
+ const template = types.array(types.anything);
+ /* tslint:enable:align */
options.match(template)(matchee).should.be.true;
});