Skip to content

Instantly share code, notes, and snippets.

@dglowinski
Created November 8, 2017 15:45
Show Gist options
  • Save dglowinski/89ce52ac6de5deb1cba9b46b1d6b98f6 to your computer and use it in GitHub Desktop.
Save dglowinski/89ce52ac6de5deb1cba9b46b1d6b98f6 to your computer and use it in GitHub Desktop.
const myApp = require('../server.js');
const request = require('supertest')(myApp);
const chai = require('chai');
chai.use(require('chai-json-schema'))
const expect = chai.expect;
describe('serverApi', function () {
const postBody = { pvtKey: "9a8de2c8850f5c499e06596dae72302968c2b919870cb884062198f4ff7a7a83" };
const result = {
type: 'object',
required:[ 'privateKey', 'publicKey'],
properties: {
privateKey: {type: 'string', pattern: "^[0-9a-zA-Z]+$"},
publicKey: {type: 'string', pattern: "^[0-9a-zA-Z]+$"},
}
};
it('returns a json with publicKey and address', function (done) {
request
.post('/web3/createNewKeys')
.type('form')
.send(postBody)
.expect(200)
.expect(res=>{
expect(res.body).to.be.jsonSchema(apiSchema(result));
})
.end(done)
});
});
const apiSchema = (resultSchema) => ({
title: 'Api response schema',
type: 'object',
required: ['result'],
properties: {
result: resultSchema
}
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment