diff options
| author | Tom Harley | 2018-04-17 17:03:14 +0100 |
|---|---|---|
| committer | Tom Harley | 2018-04-17 17:03:14 +0100 |
| commit | 44c14c13bdd7ad91a119564622b811cc70147de8 (patch) | |
| tree | 318420a6bc570bcd3c990d387411e7a205a4e677 /test | |
| parent | Merge branch 'trh/gets' of gitlab.cs.st-andrews.ac.uk:cs3099group-be-4/projec... (diff) | |
| parent | World War Files - changed precondition + filled addSubFileToFolder() function... (diff) | |
| download | medicine-44c14c13bdd7ad91a119564622b811cc70147de8.tar.gz medicine-44c14c13bdd7ad91a119564622b811cc70147de8.zip | |
Merge branch ‘trh/gets’ of gitlab.cs.st-andrews.ac.uk: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/auth.routes.test.ts | 22 | ||||
| -rw-r--r-- | test/integration/protocol.routes.test.ts | 370 | ||||
| -rw-r--r-- | test/postman.json.json | 245 | ||||
| -rw-r--r-- | test/test-db.ts | 4 | ||||
| -rw-r--r-- | test/unit/options.unit.test.ts | 58 | ||||
| -rw-r--r-- | test/unit/types.unit.test.ts | 1 |
7 files changed, 584 insertions, 168 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.e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iJoYWZlZXoiLCJwcml2aWxlZ2VJZCI6Mn19XSwicHJvamVjdHMiOltdfSwiaWF0IjoxNTIzODk1MzgzLCJleHAiOjE1MjM5MTY5ODN9.3kpxdZFReNz24MfK6AN4rc3T1vOaG9AM40RQ4-FL7xI", + "type": "text" + } + ], + "timestamp": 1523895383946, + "_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/auth.routes.test.ts b/test/integration/auth.routes.test.ts index af3f696..29c0cfc 100644 --- a/test/integration/auth.routes.test.ts +++ b/test/integration/auth.routes.test.ts @@ -65,13 +65,15 @@ const authorisationErr = { error_description: 'user does not have correct authorisation for task' }; +const base: string = '/cs3099group-be-4'; + describe('authentication', () => { before(initDatabase); context('invalid password authentication', () => { before(populateDatabase); it('should reject login to invalid endpoints', () => { return chai.request(app) - .post('/') + .post('/invalid endpoint') .send({ username: mockUser.username, password: mockUser.password, @@ -86,7 +88,7 @@ describe('authentication', () => { }); it('should reject invalid usernames', () => { return chai.request(app) - .post('/cs3099group-be-4/oauth/token') + .post(`${base}/oauth/token`) .send({ username: 'invalid', password: mockUser.password, @@ -97,7 +99,7 @@ describe('authentication', () => { }); it('should reject invalid passwords', () => { return chai.request(app) - .post('/cs3099group-be-4/oauth/token') + .post(`${base}/oauth/token`) .send({ username: mockUser.username, password: 'asasasas', @@ -108,7 +110,7 @@ describe('authentication', () => { }); it('should reject invalid grant_type', () => { return chai.request(app) - .post('/cs3099group-be-4/oauth/token') + .post(`${base}/oauth/token`) .send({ username: mockUser.username, password: mockUser.password, @@ -119,7 +121,7 @@ describe('authentication', () => { }); it('should reject empty usernames', () => { return chai.request(app) - .post('/cs3099group-be-4/oauth/token') + .post(`${base}/oauth/token`) .send({ username: '', password: mockUser.password, @@ -130,7 +132,7 @@ describe('authentication', () => { }); it('should reject empty passwords', () => { return chai.request(app) - .post('/cs3099group-be-4/oauth/token') + .post(`${base}/oauth/token`) .send({ username: mockUser.username, password: '', @@ -141,7 +143,7 @@ describe('authentication', () => { }); it('should reject empty grant_type', () => { return chai.request(app) - .post('/cs3099group-be-4/oauth/token') + .post(`${base}/oauth/token`) .send({ username: mockUser.username, password: mockUser.password, @@ -155,7 +157,7 @@ describe('authentication', () => { before(populateDatabase); it('should accept correct credentials', () => { return chai.request(app) - .post('/cs3099group-be-4/oauth/token') + .post(`${base}/oauth/token`) .send({ username: mockUser.username, password: mockUser.password, @@ -169,7 +171,7 @@ describe('authentication', () => { beforeEach(populateDatabase); beforeEach(getToken); it('should reject invalid tokens', () => { - return chai.request(app).get('/') + return chai.request(app).get(`${base}/users`) .set('Authorization', 'Bearer ' + 'invalid') .then((res) => { expect(res).to.have.status(401); @@ -178,7 +180,7 @@ describe('authentication', () => { }); }); it('should accept valid tokens', () => { - return chai.request(app).get('/') + return chai.request(app).get(`${base}/_supported_protocols_`) .set('Authorization', `Bearer ${token}`) .then((res) => { expect(res).to.have.status(200); diff --git a/test/integration/protocol.routes.test.ts b/test/integration/protocol.routes.test.ts index ebe18c2..1e8bf63 100644 --- a/test/integration/protocol.routes.test.ts +++ b/test/integration/protocol.routes.test.ts @@ -10,6 +10,7 @@ const expect: Chai.ExpectStatic = chai.expect; import { Credentials, Database, addUser, initDB, resetDB, Projec, addProjec, Filee, addFilee } from '../test-db'; import { default as User } from '../../src/db/model/User'; +import * as fs from 'fs'; // Chai-http must be imported this way: // tslint:disable-next-line:no-var-requires no-require-imports @@ -57,8 +58,7 @@ const getToken = async() => { }); }; -import { Template, alternative, array, exact, match, optional - } from '../../src/matcher/options'; +import options, { Template, alternative, array, exact, match, optional }from '../../src/matcher/options'; import { default as types } from '../../src/matcher/types'; // The general response template according to protocol @@ -82,160 +82,138 @@ const errorResponseTemplate: Template = { type MochaForEachInput = [ string, string, Template, number ]; -describe('routes : errors', () => { - before(initDatabase); - describe('GET invalid routes', () => { - // Should invalid routes also possibly be 401? - it.skip('should have response code 404', () => { - return chai.request(app).get('/invalid/route') - .set('Authorization', `Bearer ${token}`) - .catch((err) => { - expect(err.status).to.equal(404); - }); - }); - it('should conform to the error protocol', () => { - return chai.request(app).get('/invalid/route') - .set('Authorization', `Bearer ${token}`) - .catch((err) => { - expect(match(errorResponseTemplate)(err.response.body)).to.be.true; - }); - }); - }); -}); +const base: string = '/cs3099group-be-4'; -describe('routes : protocol', () => { - const base: string = '/cs3099group-be-4'; +/* tslint:disable:align */ - /* tslint:disable:align */ - - // Format: - // <method> <route> <json-response-template> <response-code> - const completeProtocol: MochaForEachInput[] = [ - ['get', '/_supported_protocols_', exact({ - supported: array(types.string), - required: array(types.string) - }), 200], - ['get', '/log', types.array({ - component: types.string, - level: alternative([ - 'info', - 'security', - 'warning', - 'error', - 'critical' - ]), - value: types.anything, - username: types.string, - timestamp: types.string - }), 200], - ['post', '/log', [{ - component: 'tesssst', - level: 'info', - value: 'sdasdasdasdasdasd' - }], 200], - ['get', '/properties', types.array({ - id: types.string, - display: optional(match({ - category: types.string, - group: types.string, - display_name: types.string, - description: types.string - })), - read_only: types.boolean, - type: alternative([ - 'string', - 'integer', - 'boolean' - ]), - value: alternative([ - types.string, - types.integer, - types.boolean - ]) - }), 200], - ['post', '/properties', null, 200], - ['get', '/user_privileges', array({ - privilege: types.string, - description: types.string, - internal: types.boolean - }), 200], - ['get', '/users', array({ - username: types.string, - privileges: array(types.string), - projects: array({ - project_name: types.string, - access_level: types.string - }), - public_user_metadata: types.anything, - private_user_metadata: types.anything, - public_admin_metadata: types.anything, - private_admin_metadata: types.anything - }), 200], - // TODO types.metadata - ['get', '/users/mock_user', { - username: types.string, - privileges: array(types.string), - projects: array({ - project_name: types.string, - access_level: types.string - }), - public_user_metadata: types.anything, - private_user_metadata: types.anything, - public_admin_metadata: types.anything, - private_admin_metadata: types.anything - }, 200], - ['post', '/users/new_user', null, 200], - ['get', '/users/mock_user/properties', { - data: optional(types.anything) - }, 200], - ['get', '/current_user', { - username: types.string, - privileges: array(types.string), - projects: array({ - project_name: types.string, - access_level: types.string - }), - public_user_metadata: types.anything, - private_user_metadata: types.anything, - public_admin_metadata: types.anything, - private_admin_metadata: types.anything - }, 200], - ['post', '/current_user', null, 200], - ['get', '/project_roles', array({ - role: types.string, - description: types.string, - internal: types.boolean - }), 200], - ['get', '/projects', array({ +// Format: +// <method> <route> <json-response-template> <response-code> +const completeProtocol: MochaForEachInput[] = [ + ['get', '/_supported_protocols_', { + supported: array(types.string), + required: array(types.string) + }, 200], + ['get', '/log', array({ + component: types.string, + level: alternative([ + 'info', + 'security', + 'warning', + 'error', + 'critical' + ]), + value: types.anything, + username: types.string, + timestamp: types.string + }), 200], + ['post', '/log', [{ + component: 'tesssst', + level: 'info', + value: 'sdasdasdasdasdasd' + }], 200], + ['get', '/properties', array({ + id: types.string, + display: optional(match({ + category: types.string, + group: types.string, + display_name: types.string, + description: types.string + })), + read_only: types.boolean, + type: alternative([ + 'string', + 'integer', + 'boolean' + ]), + value: alternative([ + types.string, + types.integer, + types.boolean + ]) + }), 200], + ['post', '/properties?action=update', null, 200], + ['get', '/user_privileges', array({ + privilege: types.string, + description: types.string, + internal: types.boolean + }), 200], + ['get', '/users', array({ + username: types.string, + privileges: types.array(types.string), + projects: types.array({ project_name: types.string, - users: array({ - username: types.string, - access_level: types.string - }), - public_metadata: types.anything, - private_metadata: optional(types.anything), - admin_metadata: optional(types.anything) - }), 200], - ['get', '/projects/mocky', { + access_level: types.string + }), + public_user_metadata: types.anything, + private_user_metadata: types.anything, + public_admin_metadata: types.anything, + private_admin_metadata: types.anything + }), 200], + // TODO types.metadata + ['get', '/users/mock_user', { + username: types.string, + privileges: array(types.string), + projects: array({ project_name: types.string, - users: array({ - username: types.string, - access_level: types.string - }), - public_metadata: types.anything, - private_metadata: types.anything, - admin_metadata: optional(types.anything) - }, 200], - ['post', '/projects/mocky', null, 200], - ['get', '/projects/mocky/properties', { - data: optional(types.anything) - }, 200], - ['get', '/projects/mocky/files/example/path', null, 200], - ['post', '/projects/mocky/files/mockyfile2', null, 200], - ['get', '/projects/mocky/files_by_id/file1', null, 200] - ]; + access_level: types.string + }), + public_user_metadata: types.anything, + private_user_metadata: types.anything, + public_admin_metadata: types.anything, + private_admin_metadata: types.anything + }, 200], + ['post', '/users/new_user', null, 200], + ['get', '/users/mock_user/properties', { + data: optional(types.anything) + }, 200], + ['get', '/current_user', { + username: types.string, + privileges: types.array(types.string), + projects: types.array({ + project_name: types.string, + access_level: types.string + }), + public_user_metadata: types.anything, + private_user_metadata: types.anything, + public_admin_metadata: types.anything, + private_admin_metadata: types.anything + }, 200], + ['post', '/current_user', null, 200], + ['get', '/project_roles', array({ + role: types.string, + description: types.string, + internal: types.boolean + }), 200], + ['get', '/projects', array({ + project_name: types.string, + users: types.array({ + username: types.string, + access_level: types.string + }), + public_metadata: types.anything, + private_metadata: optional(types.anything), + admin_metadata: optional(types.anything) + }), 200], + ['get', '/projects/mocky', { + project_name: types.string, + users: array({ + username: types.string, + access_level: types.string + }), + public_metadata: types.anything, + private_metadata: types.anything, + admin_metadata: optional(types.anything) + }, 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], + ['get', '/projects/mocky/files_by_id/file1', null, 200] +]; + +/* tslint:enable:align */ - /* tslint:enable:align */ +describe('routes : protocol', () => { before(initDatabase); beforeEach(populateDatabase); @@ -257,11 +235,19 @@ describe('routes : protocol', () => { forEach(completeProtocol).it( '%s %s should have a status %4$d', (method: string, path: string, temp: Template, resCode: number) => { - const request: ChaiHttp.Request = method === 'get' + const request: any = method === 'get' ? chai.request(app).get(base + path) - : chai.request(app).post(base + path); + : chai.request(app).post(base + path).send(temp); + /*if (path.includes('/projects/mocky/files/some_file')) { + fs.createReadStream('test/mockUI/ui.html').pipe( + request); + console.log("tasdasdas") + }*/ request.set('Authorization', `Bearer ${token}`); return request.then((res: ChaiHttp.Response) => { + if (path.includes('/projects/mocky/files/some_file')) { + //console.log("something") + } expect(res).to.have.status(resCode); }); }); @@ -270,25 +256,97 @@ describe('routes : protocol', () => { (method: string, path: string, temp: Template, resCode: number) => { const request: ChaiHttp.Request = method === 'get' ? chai.request(app).get(base + path) - : chai.request(app).post(base + path); + : chai.request(app).post(base + path).send(temp);; request.set('Authorization', `Bearer ${token}`); return request.then((res: ChaiHttp.Response) => { + if (!(match(responseTemplate)(res.body))) { + console.log(`${method} ${path} ******************`); + console.log(res.body); + console.log("^^^^^^ received || template vvvvvvvv") + console.log(responseTemplate); + console.log('--------------------------------') + } expect(match(responseTemplate)(res.body)).to.be.true; }); }); forEach(completeProtocol).it( - 'the response for %s %s should conform to its specific response protocol', + '%s %s should conform to its specific response template', (method: string, path: string, temp: Template, resCode: number) => { if (method === 'get' && temp != null) { return chai.request(app) .get(base + path) .set('Authorization', `Bearer ${token}`) .then((res: ChaiHttp.Response) => { - expect(match(temp)(res.body)).to.be.true; + if (!(match(temp)(res.body.data))) { + console.log(`${method} ${path} ******************`); + console.log(res.body.data); + console.log("^^^^^^ received || template vvvvvvvv") + console.log(temp); + console.log('--------------------------------') + } + expect(match(temp)(res.body.data)).to.be.true; }); } else { return true; } }); }); + + describe('test edge cases', () => { + before(initDatabase); + beforeEach(populateDatabase); + beforeEach(getToken); + + describe('GET invalid routes', () => { + // Should invalid routes also possibly be 401? + it.skip('should have response code 404', () => { + return chai.request(app).get('/invalid/route') + .set('Authorization', `Bearer ${token}`) + .catch((err) => { + expect(err.status).to.equal(404); + }); + }); + it('should conform to the error protocol', () => { + return chai.request(app).get('/invalid/route') + .set('Authorization', `Bearer ${token}`) + .catch((err) => { + expect(match(errorResponseTemplate)(err.response.body)).to.be.true; + }); + }); + }); + + describe('POST invalid routes', () => { + // Should invalid routes also possibly be 401? + it.skip('should have response code 404', () => { + return chai.request(app).post('/invalid/route') + .set('Authorization', `Bearer ${token}`) + .catch((err) => { + expect(err.status).to.equal(404); + }); + }); + it('should conform to the error protocol', () => { + return chai.request(app).post('/invalid/route') + .set('Authorization', `Bearer ${token}`) + .catch((err) => { + expect(match(errorResponseTemplate)(err.response.body)).to.be.true; + }); + }); + }); +/* + describe('access valid routes with invalid parameters', () => { + forEach(completeProtocol.filter((item, index, arr) => { + return (item[0] == 'post'); + })).it( + '%s %s with null body should throw error', + (method: string, path: string, temp: Template, resCode: number) => { + const request: any = chai.request(app).post(base + path); + request.set('Authorization', `Bearer ${token}`) + .then((res: any) => { + expect(res).to.have.status(400); + }).catch((reason: any) => { + expect(reason.response.body).to.eql("errererere"); + }); + }); + });*/ + }); }); 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/test-db.ts b/test/test-db.ts index 40ae438..ef980c5 100644 --- a/test/test-db.ts +++ b/test/test-db.ts @@ -112,9 +112,9 @@ export const addFilee: (database: Database, user: Credentials) => path: 'example/path', uuid: 'file1', creator: user, - type: "generic" + type: 'generic' }; await new File(mockFile).save(); return mockFile; -};
\ No newline at end of file +}; diff --git a/test/unit/options.unit.test.ts b/test/unit/options.unit.test.ts index 1925835..fd88ca6 100644 --- a/test/unit/options.unit.test.ts +++ b/test/unit/options.unit.test.ts @@ -159,5 +159,63 @@ describe('Matching:', () => { }; options.match(template, matchee).should.be.false; }); + it('accepts optional matches', () => { + const template = { + a: options.optional(types.array), + b: options.optional(types.anything) + }; + const matchee = { + b: [] + }; + 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', + 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 */ + + 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.only('Matching Arrays', () => { + /* tslint:disable:align */ + const matchee: any = ['ss']; + const template: any = types.array; + /* tslint:enable:align */ + + options.match(template)(matchee).should.be.true; + }); }); }); diff --git a/test/unit/types.unit.test.ts b/test/unit/types.unit.test.ts index ad0f99c..f18d5a1 100644 --- a/test/unit/types.unit.test.ts +++ b/test/unit/types.unit.test.ts @@ -30,6 +30,7 @@ describe('Type Checking:', () => { types.anything(1).should.be.true; types.anything('string').should.be.true; types.anything(false).should.be.true; + types.anything([]).should.be.true; }); it('accepts null', () => { types.anything(null).should.be.true; |
