Skip to content

Commit

Permalink
add check for content-type json and fix chai-related eslint errors
Browse files Browse the repository at this point in the history
  • Loading branch information
rafaelmaeuer committed Mar 17, 2021
1 parent 20fae4d commit f6ee872
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 15 deletions.
7 changes: 4 additions & 3 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,16 @@
"ecmaVersion": 2020
},
"root": true,
"plugins": ["@swrlab/eslint-plugin-swr"],
"extends": ["plugin:@swrlab/eslint-plugin-swr/recommended"],
"plugins": ["@swrlab/eslint-plugin-swr", "chai-friendly"],
"extends": ["plugin:@swrlab/eslint-plugin-swr/recommended", "plugin:chai-friendly/recommended"],
"ignorePatterns": ["docs/_SIDEBAR.md"],
"rules": {
"radix": 0,
"no-unused-vars": [
"error",
{
"argsIgnorePattern": "next"
"argsIgnorePattern": "next",
"varsIgnorePattern": "should"
}
],
"no-param-reassign": [2, { "props": false }],
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ This source code is provided under EUPL v1.2, except for the [`spdx-exceptions`]
| NPM DEV | `docsify-cli` | [MIT](https://github.com/docsifyjs/docsify-cli/blob/master/LICENSE) |
| NPM DEV | `eslint` | [MIT](https://github.com/eslint/eslint/blob/master/LICENSE) |
| NPM DEV | `eslint-plugin-swr` | [ISC](https://github.com/swrlab/eslint-plugin-swr/blob/main/package.json) |
| NPM DEV | `eslint-plugin-chai-friendly` | [MIT](https://github.com/ihordiachenko/eslint-plugin-chai-friendly/blob/master/LICENSE) |
| NPM DEV | `license-compliance` | [MIT](https://github.com/tmorell/license-compliance/blob/master/LICENSE) |
| NPM DEV | `mocha` | [MIT](https://github.com/mochajs/mocha/blob/master/LICENSE) |
| NPM DEV | `nodemon` | [MIT](https://github.com/remy/nodemon/blob/master/LICENSE) |
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
"chai-http": "^4.3.0",
"docsify-cli": "^4.4.3",
"eslint": "^7.22.0",
"eslint-plugin-chai-friendly": "^0.6.0",
"eslint-plugin-swr": "0.0.5",
"license-compliance": "^1.0.3",
"mocha": "^8.3.2",
Expand Down
5 changes: 4 additions & 1 deletion test/example.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@
*/

const expect = require('chai').expect
// Add eslint exceptions for chai
/* global describe it */

const { expect } = require('chai')

describe('Simple Math Test', () => {
it('1 + 1 = 2', () => {
Expand Down
34 changes: 23 additions & 11 deletions test/ingest.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,29 @@
*/

// Add eslint exceptions
/* eslint-disable spaced-comment */
/* eslint-disable object-shorthand */
/* global describe it */

// Require dependencies
const chai = require('chai')
const chaiHttp = require('chai-http')
const server = require('../src/ingest/index')

// Init functions
// Init chai functions
const { expect } = chai
const should = chai.should()
const expect = chai.expect

// Use chaiHttp
chai.use(chaiHttp)

// define general tests
function testResponse(res, status) {
expect(res).to.be.json
res.should.have.status(status)
}

/*
AUTH - Authentication services for Eventhub
*/
Expand Down Expand Up @@ -48,12 +59,13 @@ describe('POST /auth/login', () => {
.post('/auth/login')
.send(loginRequest)
.end((err, res) => {
res.should.have.status(200)
testResponse(res, 200)
testAuthKeys(res.body)
done()
// Store tokens for further tests
accessToken = res.body.token
refreshToken = res.body.refreshToken
process.exit(0)
})
})
})
Expand All @@ -68,7 +80,7 @@ describe('POST /auth/refresh', () => {
.post('/auth/refresh')
.send(refreshRequest)
.end((err, res) => {
res.should.have.status(200)
testResponse(res, 200)
testAuthKeys(res.body)
done()
// Store new token for further tests
Expand All @@ -89,7 +101,7 @@ if (process.env.TEST_USER_RESET) {
.post('/auth/reset')
.send(resetRequest)
.end((err, res) => {
res.should.have.status(200)
testResponse(res, 200)
done()
})
})
Expand Down Expand Up @@ -125,7 +137,7 @@ describe(`POST /events/${eventName}`, () => {
.set('Authorization', `Bearer ${accessToken}`)
.send(event)
.end((err, res) => {
res.should.have.status(201)
testResponse(res, 201)
testEventKeys(res.body)
done()
})
Expand All @@ -152,7 +164,7 @@ describe('GET /topics', () => {
.get('/topics')
.set('Authorization', `Bearer ${accessToken}`)
.end((err, res) => {
res.should.have.status(200)
testResponse(res, 200)
res.body.should.be.a('array')
res.body.every((i) => testTopicKeys(i))
topicName = res.body[0].name
Expand Down Expand Up @@ -204,7 +216,7 @@ describe('POST /subscriptions', () => {
.set('Authorization', `Bearer ${accessToken}`)
.send(subscription)
.end((err, res) => {
res.should.have.status(201)
testResponse(res, 201)
testSubscriptionKeys(res.body)
// Store subscription name for further tests
subscriptionName = res.body.name
Expand All @@ -219,7 +231,7 @@ describe('GET /subscriptions', () => {
.get('/subscriptions')
.set('Authorization', `Bearer ${accessToken}`)
.end((err, res) => {
res.should.have.status(200)
testResponse(res, 200)
res.body.should.be.a('array')
res.body.every((i) => testSubscriptionKeys(i))
done()
Expand All @@ -233,7 +245,7 @@ describe('GET /subscriptions/{name}', () => {
.get(`/subscriptions/${subscriptionName}`)
.set('Authorization', `Bearer ${accessToken}`)
.end((err, res) => {
res.should.have.status(200)
testResponse(res, 200)
testSubscriptionKeys(res.body)
done()
})
Expand All @@ -246,7 +258,7 @@ describe('DELETE /subscriptions/{name}', () => {
.delete(`/subscriptions/${subscriptionName}`)
.set('Authorization', `Bearer ${accessToken}`)
.end((err, res) => {
res.should.have.status(200)
testResponse(res, 200)
res.body.should.be.a('object')
res.body.should.have.property('valid').eql(true)
//res.body.should.have.property('trace').eql(null);
Expand Down
5 changes: 5 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1912,6 +1912,11 @@ eslint-module-utils@^2.6.0:
debug "^2.6.9"
pkg-dir "^2.0.0"

eslint-plugin-chai-friendly@^0.6.0:
version "0.6.0"
resolved "https://registry.yarnpkg.com/eslint-plugin-chai-friendly/-/eslint-plugin-chai-friendly-0.6.0.tgz#54052fab79302ed0cea76ab997351ea4809bfb77"
integrity sha512-Uvvv1gkbRGp/qfN15B0kQyQWg+oFA8buDSqrwmW3egNSk/FpqH2MjQqKOuKwmEL6w4QIQrIjDp+gg6kGGmD3oQ==

eslint-plugin-import@^2.22.0:
version "2.22.1"
resolved "https://registry.yarnpkg.com/eslint-plugin-import/-/eslint-plugin-import-2.22.1.tgz#0896c7e6a0cf44109a2d97b95903c2bb689d7702"
Expand Down

0 comments on commit f6ee872

Please sign in to comment.