diff options
| author | jw255 | 2018-02-06 15:07:46 +0000 |
|---|---|---|
| committer | jw255 | 2018-02-06 15:07:46 +0000 |
| commit | c43a1a3ab512ad24cfc603ac5e5273e8e9b30329 (patch) | |
| tree | c4c7c475d28274df36e72d54f48088eae0473d74 /test | |
| parent | started work on type checking (diff) | |
| parent | some testing (diff) | |
| download | medicine-c43a1a3ab512ad24cfc603ac5e5273e8e9b30329.tar.gz medicine-c43a1a3ab512ad24cfc603ac5e5273e8e9b30329.zip | |
Merge branch ‘testing’ into trh/payload-checker
Diffstat (limited to 'test')
| -rw-r--r-- | test/mockUI/ui.html | 126 | ||||
| -rw-r--r-- | test/nodeserver.test.ts | 111 |
2 files changed, 237 insertions, 0 deletions
diff --git a/test/mockUI/ui.html b/test/mockUI/ui.html new file mode 100644 index 0000000..6c0b9db --- /dev/null +++ b/test/mockUI/ui.html @@ -0,0 +1,126 @@ +<!DOCTYPE html> + <html> + <head> + <!--Import Google Icon Font--> + <link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet"> + <!-- Compiled and minified CSS --> + <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/materialize/0.100.2/css/materialize.min.css"> + + <!--Let browser know website is optimized for mobile--> + <meta name="viewport" content="width=device-width, initial-scale=1.0"/> + + <style> + #users, #projects_table, #create_proj {
+ margin-bottom: 5em;
+ } + </style> + </head> + + <body> + <div class="container"> + <div class="row" id="users"> + <h3>Login</h3> + <div class="input-field"> + <input id="username" type="text"> + <label for="username">Username</label> + </div> + <div class="input-field"> + <input id="password" type="password"> + <label for="password">Password</label> + </div> + <a class="waves-effect waves-light btn" id="login_btn">Login</a> + </div> + + <div class="row" id="projects"> + <h3>Projects</h3> + <table class="bordered" id="projects_table"> + <thead><tr> + <th>Name</th> + <th>Users</th> + <th>Metadata</th> + </tr></thead> + </table> + + <h5>Create Project</h5> + <div class="input-field"> + <input id="project_name" type="text" /> + <label for="project_name">Name</label> + </div> + <div class="input-field"> + <select multiple> + + </select> + <label>Select users</label> + </div> + <a class="waves-effect waves-light btn" id="create_proj">Create</a> + + <h5>Upload File to Project</h5> + <div class="input-field"> + <select> + + </select> + <label>Select Project</label> + </div> + <div class="file-field input-field"> + <div class="btn"> + <span>file</span> + <input type="file" /> + </div> + <div class="file-path-wrapper"> + <input class="file-path validate" type="text" /> + </div> + </div> + <a class="waves-effect waves-light btn" id="upload_file">Upload</a> + </div> + </div> + <!--Import jQuery before materialize.js--> + <script type="text/javascript" src="https://code.jquery.com/jquery-3.2.1.min.js"></script> + <!-- Compiled and minified JavaScript --> + <script src="https://cdnjs.cloudflare.com/ajax/libs/materialize/0.100.2/js/materialize.min.js"></script> + + <script> + //init select element + $(document).ready(function () {
+ $('select').material_select();
+ }); + + var serverUrl = "" //url needed + + //login + $('#login_btn').click(function () {
+ var username = $('#username').val();
+ var password = $('#password').val();
+
+ $.post(serverUrl + "oauth/token", {
+ "grant_type": "password", + "username": username, + "password": password
+ }, function (data, status, xhr) {
+ if (xhr.status == 200) {
+ console.log(data.token_type);
+ console.log(data.access_token);
+ console.log(data.refresh_token);
+ console.log(data.expires_in);
+ }
+ else if (xhr.status == 400) {
+ console.log(data.error);
+ console.log(data.error_description);
+ }
+
+ }) + .fail(function () {
+ console.log("request failed");
+ });
+ }); + + //show projects from database + function showProjects() {
+ $.get(serverUrl + "projects", function (data, status, xhr) {
+ for (var i = 0; i < data.length; i++) {
+ $('#projects_table > tbody').append("<tr><td>" + data[i].project_name + "<\td></tr>");
+ }
+ });
+ } + </script> + </body> + </html>
\ No newline at end of file diff --git a/test/nodeserver.test.ts b/test/nodeserver.test.ts index 3ad37e5..cc6a723 100644 --- a/test/nodeserver.test.ts +++ b/test/nodeserver.test.ts @@ -1,12 +1,52 @@ import * as mocha from 'mocha'; import * as chai from 'chai'; import chaiHttp = require('chai-http'); +const forEach = require('mocha-each'); import app from '../src/app'; +app.log_enabled = false; chai.use(chaiHttp); const expect = chai.expect; +const resp_err = '{"status": "error","error": string,"error_description": optional(string),"user_message": optional(string),"error_data": optional(anything)}'; +const resp_suc = '{"status": "success","data": anything}'; + +function checkRespStand(res){ + let suc = JSON.parse(resp_suc); + let err = JSON.parse(resp_err); + console.log(suc); + +} + +function check(res_str : string, prot_str : string) : boolean { + // parse response string + let resp = JSON.parse(res_str); + + let exact : boolean = false; + // if exact(...) + if(prot_str.indexOf("exact") == 0){ + exact = true; + prot_str = prot_str.slice(6, prot_str.length-1) + } + // loop all fields + var reg = /"(.*?)"/g + var result; + while((result = reg.exec(prot_str)) !== null) { + result = result.slice(1, result.length-1); // get rid of extra quotation marks + console.log(result); + + + } + + let prot = JSON.parse(prot_str); + + + if(prot.) + + return true; +} + describe('baseRoute', () => { it('should be json', () => { @@ -24,3 +64,74 @@ describe('baseRoute', () => { }); }); + +describe('General protocol', () => { + let complete_protocol = [ + ['get', '/_supported_protocols_' ], + ['get', '/log' ], + ['post','/log' ], + ['get' ,'/properties' ], + ['post','/properties' ], + ['get' ,'/user_privileges' ], + ['get' ,'/users' ], + ['get' ,'/users/:username' ], + ['post','/users/:username' ], + ['get' ,'/users/:username/properties' ], + ['get' ,'/current_user' ], + ['post','/current_user' ], + ['get' ,'/project_roles' ], + ['get' ,'/projects' ], + ['get' ,'/projects/:project_name' ], + ['post','/projects/:project_name' ], + ['get' ,'/projects/:project_name/properties' ], + ['get' ,'/projects/:project_name/files/:path' ], + ['post','/projects/:project_name/files/:id' ], + ['get' ,'/projects/:project_name/files_by_id/:id' ] + ]; + + describe('Checking complete Protocol', () => { + forEach(complete_protocol) + .it('%s %s should be json', (method, path) => { + if(method == 'get'){ + return chai.request(app).get(path) + .then(res => { + expect(res.type).to.eql('application/json'); + }); + }else if(method == 'post'){ + return chai.request(app).post(path) + .then(res => { + expect(res.type).to.eql('application/json'); + }); + } + }) + forEach(complete_protocol) + .it('%s %s should have a status 200', (method, path) => { + if(method == 'get'){ + return chai.request(app).get(path) + .then(res => { + expect(res).to.have.status(200); + }); + }else if(method == 'post'){ + return chai.request(app).post(path) + .then(res => { + expect(res).to.have.status(200); + }); + } + }) + forEach(complete_protocol) + .it('%s %s should conform to standard protocol', (method, path) => { + if(method == 'get'){ + return chai.request(app).get(path) + .then(res => { + expect(res).to.have.status(200); + }); + }else if(method == 'post'){ + return chai.request(app).post(path) + .then(res => { + expect(res).to.have.status(200); + }); + } + }); + + }) +}); |
