generated from BuildForSDG/js-starter
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
SME Business Profile Verification routes
- Loading branch information
1 parent
b71b6c8
commit 47a9fc0
Showing
15 changed files
with
911 additions
and
273 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,195 @@ | ||
/* eslint-disable no-underscore-dangle */ | ||
require('dotenv').config(); | ||
|
||
const fs = require('fs'); | ||
const chai = require('chai'); | ||
const chaiHttp = require('chai-http'); | ||
const assert = require('assert'); | ||
const jwt = require('jsonwebtoken'); | ||
const User = require('../../src/models/User'); | ||
const UserProfile = require('../../src/models/UserProfile'); | ||
const Smecategory = require('../../src/models/SmeCategory'); | ||
const server = require('../../src/app'); | ||
|
||
const should = chai.should(); | ||
|
||
const apiBasePath = '/api/v1'; | ||
|
||
|
||
let adminTestToken; | ||
|
||
|
||
/* Generate Test user */ | ||
|
||
|
||
const testUser = (userType) => ({ | ||
|
||
name: 'John Collins Okey', | ||
email: `${Math.random().toString(36).substr(2, 10)}@test.com`, | ||
userType, | ||
password: 'password101' | ||
|
||
}); | ||
|
||
const categoryOne = { | ||
|
||
name: 'Test Category One', | ||
description: 'Businesses that deal with minning on a large scale' | ||
}; | ||
|
||
/* Generate Admin Access token */ | ||
|
||
before(() => { | ||
adminTestToken = jwt.sign(testUser('ADMIN'), process.env.jwtKey, | ||
{ algorithm: 'HS256', expiresIn: '24h' }); | ||
}); | ||
|
||
after(async () => { | ||
// Delete created category if it still exists (Db Clean up) | ||
await Smecategory.deleteOne({ name: categoryOne.name }); | ||
}); | ||
|
||
chai.use(chaiHttp); | ||
|
||
describe('SMEFUND CATEGORY API', () => { | ||
describe('ADMIN USER ACTIVITIES', () => { | ||
/* Test that an admin can create a category */ | ||
it('Admin can create a category', (done) => { | ||
chai.request(server) | ||
|
||
.post(`${apiBasePath}/category`) | ||
|
||
.set('token', adminTestToken) | ||
|
||
.set('Content-Type', 'application/json') | ||
|
||
.send(categoryOne) | ||
|
||
.end((err, res) => { | ||
res.should.have.status(201); | ||
|
||
res.body.should.be.a('object'); | ||
|
||
res.body.status.should.be.eql('success'); | ||
|
||
done(); | ||
}); | ||
}); | ||
|
||
|
||
/* Test that two categories cannot have the same name */ | ||
it('Admin cannot create two categories with the same name', (done) => { | ||
chai.request(server) | ||
|
||
.post(`${apiBasePath}/category`) | ||
|
||
.set('token', adminTestToken) | ||
|
||
.set('Content-Type', 'application/json') | ||
|
||
.send(categoryOne) | ||
|
||
.end((err, res) => { | ||
res.should.have.status(400); | ||
|
||
res.body.should.be.a('object'); | ||
|
||
res.body.status.should.be.eql('error'); | ||
|
||
res.body.message.should.be.eql('Category already exists'); | ||
|
||
done(); | ||
}); | ||
}); | ||
|
||
/* Test that an admin can edit a category */ | ||
it('Admin can edit a category', (done) => { | ||
chai.request(server) | ||
|
||
.patch(`${apiBasePath}/category/${categoryOne.name}`) | ||
|
||
.set('token', adminTestToken) | ||
|
||
.set('Content-Type', 'application/json') | ||
|
||
.send({ | ||
description: 'Very Informative Category group' | ||
}) | ||
|
||
.end((err, res) => { | ||
res.should.have.status(200); | ||
|
||
res.body.should.be.a('object'); | ||
|
||
res.body.status.should.be.eql('success'); | ||
|
||
done(); | ||
}); | ||
}); | ||
|
||
/* Test that an admin can view all categories */ | ||
it('Admin can view a specific category', (done) => { | ||
chai.request(server) | ||
|
||
.get(`${apiBasePath}/category/${categoryOne.name}`) | ||
|
||
.set('token', adminTestToken) | ||
|
||
.set('Content-Type', 'application/json') | ||
|
||
|
||
.end((err, res) => { | ||
res.should.have.status(200); | ||
|
||
res.body.should.be.a('object'); | ||
|
||
res.body.status.should.be.eql('success'); | ||
|
||
done(); | ||
}); | ||
}); | ||
|
||
/* Test that an admin can view all categories */ | ||
it('Admin can view all categories', (done) => { | ||
chai.request(server) | ||
|
||
.get(`${apiBasePath}/categories`) | ||
|
||
.set('token', adminTestToken) | ||
|
||
.set('Content-Type', 'application/json') | ||
|
||
|
||
.end((err, res) => { | ||
res.should.have.status(200); | ||
|
||
res.body.should.be.a('object'); | ||
|
||
res.body.status.should.be.eql('success'); | ||
|
||
done(); | ||
}); | ||
}); | ||
/* Test that an admin can delete a category */ | ||
it('Admin can delete a specific category', (done) => { | ||
chai.request(server) | ||
|
||
.delete(`${apiBasePath}/category/${categoryOne.name}`) | ||
|
||
.set('token', adminTestToken) | ||
|
||
.set('Content-Type', 'application/json') | ||
|
||
|
||
.end((err, res) => { | ||
res.should.have.status(200); | ||
|
||
res.body.should.be.a('object'); | ||
|
||
res.body.status.should.be.eql('success'); | ||
|
||
done(); | ||
}); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,63 +1,63 @@ | ||
{ | ||
"name": "team-083-backend", | ||
"version": "0.0.1", | ||
"description": "Team-083 api backend for BuidforSDG project ", | ||
"keywords": [ | ||
"sdg", | ||
"Team-083", | ||
"Api" | ||
], | ||
"directories": { | ||
"test": "__tests__" | ||
}, | ||
"private": false, | ||
"_commented": "main dist/index.js", | ||
"main": "src/index.js", | ||
"scripts": { | ||
"test": "mocha __tests__ --recursive --bail --timeout 10000 --exit", | ||
"lint": "eslint \"src/**/*.js\"", | ||
"start": "node src/index", | ||
"dev": "nodemon src/index" | ||
}, | ||
"author": { | ||
"name": "Build For SDG", | ||
"email": "[email protected]" | ||
}, | ||
"homepage": "https://github.com/BuildForSDG/Team-083-Backend#readme", | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/BuildForSDG/Team-083-Backend.git" | ||
}, | ||
"bugs": { | ||
"url": "https://github.com/BuildForSDG/Team-083-Backend/issues" | ||
}, | ||
"license": "MIT", | ||
"dependencies": { | ||
"bcrypt": "^4.0.1", | ||
"body-parser": "^1.19.0", | ||
"chai": "^4.2.0", | ||
"chai-http": "^4.3.0", | ||
"dotenv": "^8.2.0", | ||
"express": "^4.17.1", | ||
"express-async-errors": "^3.1.1", | ||
"istanbul": "^0.4.5", | ||
"jsonwebtoken": "^8.5.1", | ||
"mocha": "^7.1.2", | ||
"mocha-lcov-reporter": "^1.3.0", | ||
"mongoose": "^5.9.12", | ||
"multer": "^1.4.2", | ||
"uuidv1": "^1.6.14", | ||
"validator": "^13.0.0", | ||
"winston": "^3.2.1", | ||
"winston-mongodb": "^5.0.1" | ||
}, | ||
"devDependencies": { | ||
"eslint": "^6.8.0", | ||
"eslint-config-airbnb-base": "^14.1.0", | ||
"eslint-plugin-import": "^2.20.2", | ||
"nodemon": "^2.0.3" | ||
}, | ||
"browserslist": [ | ||
"last 1 Chrome versions" | ||
] | ||
} | ||
"name": "team-083-backend", | ||
"version": "0.0.1", | ||
"description": "Team-083 api backend for BuidforSDG project ", | ||
"keywords": [ | ||
"sdg", | ||
"Team-083", | ||
"Api" | ||
], | ||
"directories": { | ||
"test": "__tests__" | ||
}, | ||
"private": false, | ||
"_commented": "main dist/index.js", | ||
"main": "src/index.js", | ||
"scripts": { | ||
"test": "mocha __tests__ --recursive --bail --timeout 100000 --exit", | ||
"lint": "eslint \"src/**/*.js\"", | ||
"start": "node src/index", | ||
"dev": "nodemon src/index" | ||
}, | ||
"author": { | ||
"name": "Build For SDG", | ||
"email": "[email protected]" | ||
}, | ||
"homepage": "https://github.com/BuildForSDG/Team-083-Backend#readme", | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/BuildForSDG/Team-083-Backend.git" | ||
}, | ||
"bugs": { | ||
"url": "https://github.com/BuildForSDG/Team-083-Backend/issues" | ||
}, | ||
"license": "MIT", | ||
"dependencies": { | ||
"bcrypt": "^4.0.1", | ||
"body-parser": "^1.19.0", | ||
"chai": "^4.2.0", | ||
"chai-http": "^4.3.0", | ||
"dotenv": "^8.2.0", | ||
"express": "^4.17.1", | ||
"express-async-errors": "^3.1.1", | ||
"istanbul": "^0.4.5", | ||
"jsonwebtoken": "^8.5.1", | ||
"mocha": "^7.1.2", | ||
"mocha-lcov-reporter": "^1.3.0", | ||
"mongoose": "^5.9.12", | ||
"multer": "^1.4.2", | ||
"uuidv1": "^1.6.14", | ||
"validator": "^13.0.0", | ||
"winston": "^3.2.1", | ||
"winston-mongodb": "^5.0.1" | ||
}, | ||
"devDependencies": { | ||
"eslint": "^6.8.0", | ||
"eslint-config-airbnb-base": "^14.1.0", | ||
"eslint-plugin-import": "^2.20.2", | ||
"nodemon": "^2.0.3" | ||
}, | ||
"browserslist": [ | ||
"last 1 Chrome versions" | ||
] | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.