diff options
| author | josh97josh | 2018-04-20 11:53:37 +0100 |
|---|---|---|
| committer | josh97josh | 2018-04-20 11:53:37 +0100 |
| commit | af7934c3852bbde45210dd0c475817b8f20ddefc (patch) | |
| tree | 39ae972ea75cfc0033161b54eb26192bec14d353 /test | |
| parent | small fixes (diff) | |
| parent | reduced # of failing tests (diff) | |
| download | medicine-af7934c3852bbde45210dd0c475817b8f20ddefc.tar.gz medicine-af7934c3852bbde45210dd0c475817b8f20ddefc.zip | |
Merge branch ‘trh/gets’ of ssh://localhost:2222/cs3099group-be-4/project-code into trh/gets
Diffstat (limited to 'test')
| -rw-r--r-- | test/JH_environment.json | 52 | ||||
| -rw-r--r-- | test/integration/protocol.routes.test.ts | 32 | ||||
| -rw-r--r-- | test/postman.json.json | 245 | ||||
| -rw-r--r-- | test/unit/options.unit.test.ts | 162 |
4 files changed, 402 insertions, 89 deletions
diff --git a/test/JH_environment.json b/test/JH_environment.json new file mode 100644 index 0000000..bf72d78 --- /dev/null +++ b/test/JH_environment.json @@ -0,0 +1,52 @@ +{ + "id": "ddad923b-9750-c337-ff49-6ee328a72e20", + "name": "JH", + "values": [ + { + "enabled": true, + "key": "host", + "value": "http://localhost:3000", + "type": "text" + }, + { + "enabled": true, + "key": "endpoint", + "value": "cs3099group-be-4", + "type": "text" + }, + { + "enabled": true, + "key": "dummy_admin_username", + "value": "hafeez", + "type": "text" + }, + { + "enabled": true, + "key": "dummy_admin_pass", + "value": "pass", + "type": "text" + }, + { + "enabled": true, + "key": "dummy_project", + "value": "abc", + "type": "text" + }, + { + "enabled": true, + "key": "access_token", + "value": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJvYmplY3QiOnsidXNlcm5hbWUiOiJoYWZlZXoiLCJwYXNzd29yZEludGVybmFsIjpudWxsLCJjcmVhdGlvbkRhdGUiOiIyMDE4LTA0LTE2VDE2OjExOjU5LjU0M1oiLCJ1cGRhdGVkQXQiOiIyMDE4LTA0LTE2VDE2OjExOjU5LjU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, + "_postman_variable_scope": "environment", + "_postman_exported_at": "2018-04-16T16:30:59.939Z", + "_postman_exported_using": "Postman/5.5.2" +}
\ No newline at end of file diff --git a/test/integration/protocol.routes.test.ts b/test/integration/protocol.routes.test.ts index 1e8bf63..a371fd5 100644 --- a/test/integration/protocol.routes.test.ts +++ b/test/integration/protocol.routes.test.ts @@ -94,16 +94,19 @@ const completeProtocol: MochaForEachInput[] = [ required: array(types.string) }, 200], ['get', '/log', array({ + user: optional(types.string), component: types.string, level: alternative([ + 'debug', 'info', 'security', 'warning', 'error', - 'critical' + 'critical', + 'success' ]), - value: types.anything, - username: types.string, + message: types.anything, + label: optional(types.string), timestamp: types.string }), 200], ['post', '/log', [{ @@ -116,22 +119,23 @@ const completeProtocol: MochaForEachInput[] = [ display: optional(match({ category: types.string, group: types.string, - display_name: types.string, + displayName: types.string, description: types.string })), - read_only: types.boolean, + readOnly: types.boolean, type: alternative([ 'string', 'integer', 'boolean' ]), - value: alternative([ + valueInternal: alternative([ types.string, types.integer, types.boolean ]) }), 200], - ['post', '/properties?action=update', null, 200], + ['post', '/properties?action=update', + [{id: 'new_prop', value: 'some_value'}], 200], ['get', '/user_privileges', array({ privilege: types.string, description: types.string, @@ -139,8 +143,8 @@ const completeProtocol: MochaForEachInput[] = [ }), 200], ['get', '/users', array({ username: types.string, - privileges: types.array(types.string), - projects: types.array({ + privileges: array(types.string), + projects: array({ project_name: types.string, access_level: types.string }), @@ -168,8 +172,8 @@ const completeProtocol: MochaForEachInput[] = [ }, 200], ['get', '/current_user', { username: types.string, - privileges: types.array(types.string), - projects: types.array({ + privileges: array(types.string), + projects: array({ project_name: types.string, access_level: types.string }), @@ -186,7 +190,7 @@ const completeProtocol: MochaForEachInput[] = [ }), 200], ['get', '/projects', array({ project_name: types.string, - users: types.array({ + users: array({ username: types.string, access_level: types.string }), @@ -206,8 +210,8 @@ const completeProtocol: MochaForEachInput[] = [ }, 200], ['post', '/projects/mocky', null, 200], ['get', '/projects/mocky/properties', null, 200], - ['get', '/projects/mocky/files/example/path', null, 200], - ['post', '/projects/mocky/files/some_file?action=overwrite', {}, 200], + ['post', '/projects/mocky/files/folder+some_file?action=overwrite', {}, 200], + ['get', '/projects/mocky/files/folder+some_file', null, 200], ['get', '/projects/mocky/files_by_id/file1', null, 200] ]; diff --git a/test/postman.json.json b/test/postman.json.json new file mode 100644 index 0000000..14771e0 --- /dev/null +++ b/test/postman.json.json @@ -0,0 +1,245 @@ +{ + "variables": [], + "info": { + "name": "JH", + "_postman_id": "d9fad1ce-92af-fc2c-ff74-074fc681c7ee", + "description": "", + "schema": "https://schema.getpostman.com/json/collection/v2.0.0/collection.json" + }, + "item": [ + { + "name": "authorised", + "description": "", + "item": [ + { + "name": "/projects", + "request": { + "url": "{{host}}/{{endpoint}}/projects", + "method": "GET", + "header": [ + { + "key": "", + "value": "", + "disabled": true + } + ], + "body": { + "mode": "raw", + "raw": "" + }, + "description": "" + }, + "response": [] + }, + { + "name": "/log", + "request": { + "url": "{{host}}/{{endpoint}}/log", + "method": "GET", + "header": [ + { + "key": "", + "value": "", + "disabled": true + } + ], + "body": { + "mode": "raw", + "raw": "" + }, + "description": "" + }, + "response": [] + }, + { + "name": "/_supported_protocols", + "request": { + "url": "{{host}}/{{endpoint}}/_supported_protocols_", + "method": "GET", + "header": [ + { + "key": "Authorization", + "value": "Bearer {{access_token}}", + "description": "", + "disabled": true + } + ], + "body": {}, + "description": "" + }, + "response": [] + }, + { + "name": "/project_roles", + "request": { + "url": "{{host}}/{{endpoint}}/project_roles", + "method": "GET", + "header": [ + { + "key": "Authorization", + "value": "Bearer {{access_token}}", + "description": "", + "disabled": true + } + ], + "body": {}, + "description": "" + }, + "response": [] + }, + { + "name": "/projects/", + "request": { + "url": "{{host}}/{{endpoint}}/projects/{{dummy_project}}", + "method": "POST", + "header": [ + { + "key": "Content-Type", + "value": "application/json", + "description": "" + }, + { + "key": "Authorization", + "value": "Bearer {{access_token}}", + "description": "" + } + ], + "body": { + "mode": "raw", + "raw": "{}" + }, + "description": "" + }, + "response": [] + }, + { + "name": "/projects/abc/files_by_id", + "request": { + "url": "{{host}}/{{endpoint}}/projects/{{dummy_project}}/files_by_id/d124ef49-e9e3-4794-bf50-76f40797b5d5", + "method": "GET", + "header": [ + { + "key": "Authorization", + "value": "Bearer {{access_token}}", + "description": "" + }, + { + "key": "Content-Type", + "value": "image/png", + "description": "", + "disabled": true + } + ], + "body": { + "mode": "formdata", + "formdata": [ + { + "key": "pres", + "description": "", + "type": "file", + "src": "triangle_down_black.png" + } + ] + }, + "description": "" + }, + "response": [] + }, + { + "name": "/projects/abc/files", + "request": { + "url": "{{host}}/{{endpoint}}/projects/{{dummy_project}}/files/path/to/image.png", + "method": "POST", + "header": [ + { + "key": "Authorization", + "value": "Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJvYmplY3QiOnsidXNlcm5hbWUiOiJoYWZlZXoiLCJwYXNzd29yZEludGVybmFsIjpudWxsLCJjcmVhdGlvbkRhdGUiOiIyMDE4LTA0LTE2VDEyOjA1OjUyLjQ2N1oiLCJ1cGRhdGVkQXQiOiIyMDE4LTA0LTE2VDEyOjA1OjUyLjQ2N1oiLCJ1c2VyR3JvdXBzIjpbeyJpZCI6MSwibmFtZSI6ImxvZ2dpbmciLCJjYW5DcmVhdGVVc2VycyI6bnVsbCwiY2FuRGVsZXRlVXNlcnMiOm51bGwsImNhbkVkaXRVc2VycyI6bnVsbCwiY2FuQ3JlYXRlUHJvamVjdHMiOm51bGwsImNhbkRlbGV0ZVByb2plY3RzIjpudWxsLCJjYW5FZGl0UHJvamVjdHMiOm51bGwsImNhbkFjY2Vzc0xvZ3MiOnRydWUsImlzSW50ZXJuYWwiOmZhbHNlLCJkZXNjcmlwdGlvbiI6IkFsbG93cyBQb3N0IHRvIExvZyIsIlVzZXJIYXNQcml2aWxlZ2UiOnsidXNlcm5hbWUiOiJoYWZlZXoiLCJwcml2aWxlZ2VJZCI6MX19LHsiaWQiOjIsIm5hbWUiOiJhZG1pbiIsImNhbkNyZWF0ZVVzZXJzIjp0cnVlLCJjYW5EZWxldGVVc2VycyI6dHJ1ZSwiY2FuRWRpdFVzZXJzIjp0cnVlLCJjYW5DcmVhdGVQcm9qZWN0cyI6dHJ1ZSwiY2FuRGVsZXRlUHJvamVjdHMiOnRydWUsImNhbkVkaXRQcm9qZWN0cyI6dHJ1ZSwiY2FuQWNjZXNzTG9ncyI6bnVsbCwiaXNJbnRlcm5hbCI6ZmFsc2UsImRlc2NyaXB0aW9uIjoiU3lzdGVtcyBhZG1pbiIsIlVzZXJIYXNQcml2aWxlZ2UiOnsidXNlcm5hbWUiOiJoYWZlZXoiLCJwcml2aWxlZ2VJZCI6Mn19XSwicHJvamVjdHMiOltdfSwiaWF0IjoxNTIzODgwMzU2LCJleHAiOjE1MjM5MDE5NTZ9.LrRWCzjBQmPtEkthmPJvVdl6XsYqA4Myqw-VFHMbQ8o", + "description": "" + }, + { + "key": "Content-Type", + "value": "image/png", + "description": "" + } + ], + "body": { + "mode": "formdata", + "formdata": [ + { + "key": "triangle", + "description": "", + "type": "file", + "src": "triangle_down_black.png" + } + ] + }, + "description": "" + }, + "response": [] + }, + { + "name": "/", + "request": { + "url": "{{host}}/", + "method": "GET", + "header": [], + "body": {}, + "description": "" + }, + "response": [] + } + ] + }, + { + "name": "/oauth/token", + "event": [ + { + "listen": "test", + "script": { + "type": "text/javascript", + "exec": [ + "let res = JSON.parse(responseBody);", + "postman.setEnvironmentVariable(\"access_token\", res.access_token);", + "postman.setEnvironmentVariable(\"refresh_token\", res.refresh_token);" + ] + } + } + ], + "request": { + "url": "{{host}}/{{endpoint}}/oauth/token", + "method": "POST", + "header": [ + { + "key": "Content-Type", + "value": "application/x-www-form-urlencoded" + } + ], + "body": { + "mode": "urlencoded", + "urlencoded": [ + { + "key": "grant_type", + "value": "password", + "description": "", + "type": "text" + }, + { + "key": "username", + "value": "{{dummy_admin_username}}", + "description": "", + "type": "text" + }, + { + "key": "password", + "value": "{{dummy_admin_pass}}", + "description": "", + "type": "text" + } + ] + }, + "description": "wefrwrbjk;" + }, + "response": [] + } + ] +}
\ No newline at end of file diff --git a/test/unit/options.unit.test.ts b/test/unit/options.unit.test.ts index 4a85c2f..a442c38 100644 --- a/test/unit/options.unit.test.ts +++ b/test/unit/options.unit.test.ts @@ -10,8 +10,9 @@ import * as chai from 'chai'; chai.should(); -import * as options from '../../src/matcher/options'; -import { default as types } from '../../src/matcher/types'; +import { anything, boolean, not_present, number, string +} from '../../src/matcher'; +import { array, match, optional } from '../../src/matcher/options'; // tslint:disable-next-line:no-require-imports @@ -20,115 +21,115 @@ describe('Matching:', () => { context('for literals', () => { context('accepts matching', () => { it('strings', () => { - options.match('a', 'a').should.be.true; + match('a', 'a').should.be.true; }); it('numbers', () => { - options.match(3, 3).should.be.true; + match(3, 3).should.be.true; }); it('boolean values', () => { - options.match(true, true).should.be.true; + match(true, true).should.be.true; }); it('null to null', () => { - options.match(null, null).should.be.true; + match(null, null).should.be.true; }); }); context('rejects', () => { it('different strings', () => { - options.match('x', 'y').should.be.false; + match('x', 'y').should.be.false; }); it('different numbers', () => { - options.match(20, 42).should.be.false; + match(20, 42).should.be.false; }); it('different boolean values', () => { - options.match(true, false).should.be.false; + match(true, false).should.be.false; }); it('different types', () => { - options.match('55', 55).should.be.false; + match('55', 55).should.be.false; }); it('null matched with non-null values', () => { - options.match(null, false).should.be.false; + match(null, false).should.be.false; }); it('non-null values matched with null', () => { - options.match(0, null).should.be.false; + match(0, null).should.be.false; }); }); }); context('for checker functions', () => { context('accepts', () => { it('values that succeed the checker function', () => { - options.match(types.number, 9).should.be.true; + match(number, 9).should.be.true; }); }); context('rejects', () => { it('values that do not succeed the checker function', () => { - options.match(types.boolean, 'true').should.be.false; + match(boolean, 'true').should.be.false; }); }); }); it('accepts basic things', () => { const template = { - a: types.string + a: string }; const matchee = { a: 'yes' }; - options.match(template, matchee).should.be.true; + match(template, matchee).should.be.true; }); it('accepts objects with superfluous properties', () => { const template = { - a: types.number + a: number }; const matchee = { a: 40, b: 20 }; - options.match(template, matchee).should.be.true; + match(template, matchee).should.be.true; }); it('rejects objects missing some properties', () => { const template = { - a: types.boolean, - b: types.number, - c: types.number + a: boolean, + b: number, + c: number }; const matchee = { b: 5 }; - options.match(template, matchee).should.be.false; + match(template, matchee).should.be.false; }); it('accepts objects that omit not_present properties', () => { const template = { - a: types.number, - b: types.not_present, - c: types.not_present + a: number, + b: not_present, + c: not_present }; const matchee = { a: 4 }; - options.match(template, matchee).should.be.true; + match(template, matchee).should.be.true; }); it('rejects empty objects for non-empty templates', () => { const template = { - a: types.boolean + a: boolean }; const matchee = { }; - options.match(template, matchee).should.be.false; + match(template, matchee).should.be.false; }); it('accepts empty objects for empty templates', () => { const template = { }; const matchee = { }; - options.match(template, matchee).should.be.true; + match(template, matchee).should.be.true; }); it('accepts nested objects that match', () => { const template = { - a: types.number, + a: number, b: { - ba: types.string, - bb: types.string + ba: string, + bb: string }, - c: types.boolean + c: boolean }; const matchee = { a: 432, @@ -139,7 +140,7 @@ describe('Matching:', () => { c: true, x: false }; - options.match(template, matchee).should.be.true; + match(template, matchee).should.be.true; }); it('accepts literal matches', () => { const template = { @@ -148,7 +149,7 @@ describe('Matching:', () => { const matchee = { a: 'literal' }; - options.match(template, matchee).should.be.true; + match(template, matchee).should.be.true; }); it('rejects incorrect literal matches', () => { const template = { @@ -157,65 +158,76 @@ describe('Matching:', () => { const matchee = { g: 80 }; - options.match(template, matchee).should.be.false; + match(template, matchee).should.be.false; }); it('accepts optional matches', () => { const template = { - a: options.optional(types.array), - b: options.optional(types.anything) + a: optional(number), + b: optional(anything) }; const matchee = { b: [] }; - options.match(template)(matchee).should.be.true; + 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', - description: 'Allows Post to Log', - internal: false } ] }; + const matchee = { + status: 'success', + data: [ + { + privilege: 'admin', + description: 'null', + internal: false + }, + { + privilege: 'logging', + description: 'Allows Post to Log', + internal: false + } + ] + }; const template = { - status: types.string, - data: options.optional(types.anything), - error: options.optional(types.string), - error_description: options.optional(types.string), - user_message: options.optional(types.string), - error_data: options.optional(types.anything) - }; - /* tslint:enable:align */ + status: string, + data: optional(anything), + error: optional(string), + error_description: optional(string), + user_message: optional(string), + error_data: optional(anything) + }; - options.match(template)(matchee).should.be.true; + 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' }, + 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 + admin_metadata: {} + }]; + const template = array({ + project_name: string, + users: array({ + username: string, + access_level: string }), - public_metadata: types.anything, - private_metadata: options.optional(types.anything), - admin_metadata: options.optional(types.anything) + public_metadata: anything, + private_metadata: optional(anything), + admin_metadata: optional(anything) }); - /* tslint:enable:align */ - options.match(template)(matchee).should.be.true; + 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 */ + it('Matching Arrays', () => { + const matchee: string[] = ['ss']; + const template = array(string); - options.match(template)(matchee).should.be.true; + match(template)(matchee).should.be.true; }); }); }); |
