11/*global describe, it*/
22import * as chai from 'chai' ;
3- import { hello , getHelloSchema } from "../../../src/api/hello.js" ;
4- import { getSimpleGetReply , getSimpleGETRequest } from '../data/simple-request.js' ;
3+ import { hello , getHelloSchema , helloPost , getHelloPostSchema } from "../../../src/api/hello.js" ;
4+ import { getSimpleGetReply , getSimpleGETRequest , getSimplePOSTReply , getSimplePOSTRequest } from '../data/simple-request.js' ;
55import Ajv from "ajv" ;
66
77export const AJV = new Ajv ( ) ;
@@ -16,7 +16,7 @@ describe('unit Tests for hello api', function () {
1616 expect ( helloResponse ) . eql ( { message : 'hello rambo' } ) ;
1717 } ) ;
1818
19- it ( 'should validate schemas for sample request/responses' , async function ( ) {
19+ it ( 'should validate schemas for sample GET request/responses' , async function ( ) {
2020 let request = getSimpleGETRequest ( ) ;
2121 // request
2222 const requestValidator = AJV . compile ( getHelloSchema ( ) . schema . querystring ) ;
@@ -29,4 +29,18 @@ describe('unit Tests for hello api', function () {
2929 let response = await hello ( getSimpleGETRequest ( ) , getSimpleGetReply ( ) ) ;
3030 expect ( successResponseValidator ( response ) ) . to . be . true ;
3131 } ) ;
32+
33+ it ( 'should validate schemas for sample POST request/responses' , async function ( ) {
34+ let request = getSimplePOSTRequest ( ) ;
35+ // request
36+ const requestValidator = AJV . compile ( getHelloPostSchema ( ) . schema . body ) ;
37+ expect ( requestValidator ( request . body ) ) . to . be . true ;
38+ // message too long validation
39+ request . body . name = "a name that is too long" ;
40+ expect ( requestValidator ( request . body ) ) . to . be . false ;
41+ // response
42+ const successResponseValidator = AJV . compile ( getHelloPostSchema ( ) . schema . response [ "200" ] ) ;
43+ let response = await helloPost ( getSimplePOSTRequest ( ) , getSimplePOSTReply ( ) ) ;
44+ expect ( successResponseValidator ( response ) ) . to . be . true ;
45+ } ) ;
3246} ) ;
0 commit comments