Skip to content

Commit

Permalink
test for #356
Browse files Browse the repository at this point in the history
  • Loading branch information
cdimascio committed Aug 27, 2020
1 parent a5e482b commit 25263c9
Show file tree
Hide file tree
Showing 3 changed files with 118 additions and 1 deletion.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
46 changes: 46 additions & 0 deletions test/user.submitted/campaign.spec.ts
Original file line number Diff line number Diff line change
@@ -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);
});
});
71 changes: 71 additions & 0 deletions test/user.submitted/campaign.yaml
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 25263c9

Please sign in to comment.