Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var request = require('supertest');
- var config = require('../config/config');
- var AdminUser = require('../models/Authmodel');
- function configureAuth(test_suite) {
- var url = "localhost:" + config.port;
- var email = "test@test.com";
- var password = "test_password";
- var admin;
- var token;
- describe("Signup User", function() {
- it("should signup new user", function(done) {
- request(url)
- .post('/auth/signup')
- .send({
- email: email,
- password: password
- })
- .expect(200)
- .end(function(){
- done();
- });
- });
- it("should login the user", function(done) {
- request(url)
- .post('/auth/login')
- .send({
- email: email,
- password: password
- })
- .expect(200)
- .end(function(err,res){
- if(err)
- throw(err);
- res.body.should.have.property('token');
- token = res.body.token;
- done();
- });
- });
- it("should retrieve admin document", function(done) {
- AdminUser.findOne({email: email}, function(err, dbAdmin) {
- if(err)
- throw(err);
- admin = dbAdmin;
- done();
- });
- });
- });
- // Call the actual test suite, pass it the auth credentials.
- describe("Test Suite", function() {
- it("should run the test suite", function(done) {
- // No matter what the timeout is set to it still exceeds it
- this.timeout(5000);
- test_suite({
- email: email,
- password: password,
- token: token,
- admin: admin
- }, done);
- });
- });
- describe("Clear Admins", function() {
- it("should clear the admin table", function(done) {
- AdminUser.remove({email: email}, function(err) {
- if(err)
- throw(err);
- done();
- });
- });
- });
- };
- module.exports = configureAuth;
- var request = require('supertest');
- var config = require('../config/config');
- // Wrapper that creates admin user to allow api calls
- var ConfigureAuth = require('./ConfigureAuth');
- // Test data
- var templateForm = {...}
- var submittedForm = {...}
- ConfigureAuth(
- function(credentials, exit) {
- var url = "localhost:" + config.port;
- var templateFormId = null;
- describe("Form Templates", function() {
- describe('POST /api/form/template', function(){
- it('should save the template', function(done){
- request(url)
- .post('/api/form/template')
- .query({email: credentials.email, token: credentials.token})
- .send({
- _admin_id: credentials.admin._id,
- template: templateForm,
- })
- .end(function(err, res){
- templateFormId = res.body._id;
- res.body.should.have.property('_admin_id').and.be.equal(''+credentials.admin._id);
- res.body.should.have.property('template').and.be.instanceof(Object);
- done();
- });
- });
- });
- describe('GET /api/form/template/:id', function(){
- it('Should respond with template data', function(done){
- request(url)
- .get('/api/form/template/' + templateFormId)
- .query({email: credentials.email, token: credentials.token})
- .end(function(err, res){
- ...
- done();
- });
- });
- });
- describe('GET /api/form/template/company/:id', function(){
- it('Should respond with company template data', function(done){
- request(url)
- .get('/api/form/template/company/' + credentials.admin._id)
- .query({email: credentials.email, token: credentials.token})
- .end(function(err, res){
- ...
- done();
- });
- });
- });
- describe('DELETE /api/form/template/:template_id', function(){
- it('Should delete the template data', function(done){
- request(url)
- .delete('/api/form/template/' + templateFormId)
- .query({email: credentials.email, token: credentials.token})
- .end(function(err, res){
- ...
- done();
- });
- });
- });
- });
- describe("Submitted Forms", function() {
- describe('POST /api/form/patient', function(){
- it('should save submitted form', function(done){
- request(url)
- .post('/api/form/patient')
- .query({email: credentials.email, token: credentials.token})
- .send({
- _admin_id: credentials.admin._id,
- form: submittedForm,
- firstName: "Jimbo",
- lastName: "Cruise",
- patientEmail: "jcruise@tomcruise.com",
- })
- .end(function(err, res){
- ...
- submittedFormId = res.body._id;
- done();
- });
- });
- });
- describe('GET /api/form/:form_id', function(){
- it('should respond with submitted form data', function(done){
- request(url)
- .get('/api/form/patient/' + submittedFormId)
- .query({email: credentials.email, token: credentials.token})
- .end(function(err, res){
- res.body.should.have.property('_id');
- ...
- done();
- });
- });
- });
- });
- after(function() {
- exit();
- });
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement