From 25263c9e29382c4966854945cc672c8928e716f2 Mon Sep 17 00:00:00 2001 From: Carmine DiMascio Date: Thu, 27 Aug 2020 18:29:00 -0400 Subject: [PATCH] test for #356 --- package.json | 2 +- test/user.submitted/campaign.spec.ts | 46 ++++++++++++++++++ test/user.submitted/campaign.yaml | 71 ++++++++++++++++++++++++++++ 3 files changed, 118 insertions(+), 1 deletion(-) create mode 100644 test/user.submitted/campaign.spec.ts create mode 100644 test/user.submitted/campaign.yaml diff --git a/package.json b/package.json index e2c2c44f..7fe18e59 100644 --- a/package.json +++ b/package.json @@ -6,7 +6,7 @@ "scripts": { "compile": "rm -rf dist/ && tsc", "compile:windows": "rmdir dist /s /q & tsc", - "test": "TS_NODE_FILES=true mocha -r source-map-support/register -r ts-node/register --files --recursive test/**/*.spec.ts", + "test": "TS_NODE_FILES=true mocha -r source-map-support/register -r ts-node/register --files --recursive test/**/**/*.spec.ts", "test:debug": "TS_NODE_FILES=true mocha -r source-map-support/register -r ts-node/register --inspect-brk --files --recursive test/**/*.spec.ts", "test:windows": "set TS_NODE_FILES=true & mocha -r source-map-support/register -r ts-node/register --files --recursive test/**/*.spec.ts", "test:coverage": "TS_NODE_FILES=true nyc mocha -r source-map-support/register -r ts-node/register --recursive test/**/*.spec.ts", diff --git a/test/user.submitted/campaign.spec.ts b/test/user.submitted/campaign.spec.ts new file mode 100644 index 00000000..e644464d --- /dev/null +++ b/test/user.submitted/campaign.spec.ts @@ -0,0 +1,46 @@ +import * as path from 'path'; +import * as express from 'express'; +import { expect } from 'chai'; +import * as request from 'supertest'; +import { createApp } from '../common/app'; +import * as packageJson from '../../package.json'; + +describe(packageJson.name, () => { + let app = null; + + before(async () => { + // Set up the express app + const apiSpec = path.join(__dirname, 'campaign.yaml'); + app = await createApp({ apiSpec }, 3005, (app) => + app.use( + express.Router().post(`/campaign`, (req, res) => + res.status(201).json({ + id: 123, + name: req.body.name, + description: req.body.description, + startDate: req.body.startDate, + createdAt: req.body.startDate, + updatedAt: req.body.updatedAt, + }), + ), + ), + ); + }); + + after(() => { + app.server.close(); + }); + + it('create campaign should return 201', async () => { + console.log(`campaign`); + return request(app) + .post(`/campaign`) + .send({ + name: 'test', + description: 'description', + startDate: '2020-08-25T20:37:33.117Z', + endDate: '2020-08-25T20:37:33.117Z', + }) + .expect(201); + }); +}); diff --git a/test/user.submitted/campaign.yaml b/test/user.submitted/campaign.yaml new file mode 100644 index 00000000..d6cedd54 --- /dev/null +++ b/test/user.submitted/campaign.yaml @@ -0,0 +1,71 @@ +openapi: 3.0.2 +servers: + - url: / +info: + description: Campaign API + version: 0.0.1 + title: Campaign API +paths: + /campaign: + post: + summary: Create campaign + requestBody: + required: true + content: + application/json: + schema: + $ref: '#/components/schemas/CreateCampaign' + responses: + '201': + description: Campaign successfully created + content: + application/json: + schema: + $ref: '#/components/schemas/CampaignResponse' +components: + schemas: + CampaignResponse: + type: object + required: + - id + - name + - description + - startDate + - createdAt + - updatedAt + properties: + id: + type: integer + name: + type: string + description: + type: string + startDate: + type: string + format: date-time + endDate: + type: string + format: date-time + createdAt: + type: string + format: date-time + updateAt: + type: string + format: date-time + CreateCampaign: + type: object + required: + - name + - description + - startDate + properties: + name: + type: string + description: + type: string + startDate: + type: string + format: date-time + endDate: + type: string + format: date-time \ No newline at end of file