Advertisement
Guest User

Untitled

a guest
Feb 27th, 2015
214
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.44 KB | None | 0 0
  1. var request = require('supertest');
  2.  
  3. var config = require('../config/config');
  4.  
  5. var AdminUser = require('../models/Authmodel');
  6.  
  7.  
  8.  
  9. function configureAuth(test_suite) {
  10. var url = "localhost:" + config.port;
  11.  
  12. var email = "test@test.com";
  13. var password = "test_password";
  14.  
  15. var admin;
  16. var token;
  17.  
  18. describe("Signup User", function() {
  19. it("should signup new user", function(done) {
  20. request(url)
  21. .post('/auth/signup')
  22. .send({
  23. email: email,
  24. password: password
  25. })
  26. .expect(200)
  27. .end(function(){
  28. done();
  29. });
  30. });
  31.  
  32. it("should login the user", function(done) {
  33. request(url)
  34. .post('/auth/login')
  35. .send({
  36. email: email,
  37. password: password
  38. })
  39. .expect(200)
  40. .end(function(err,res){
  41. if(err)
  42. throw(err);
  43. res.body.should.have.property('token');
  44. token = res.body.token;
  45. done();
  46. });
  47. });
  48.  
  49. it("should retrieve admin document", function(done) {
  50. AdminUser.findOne({email: email}, function(err, dbAdmin) {
  51. if(err)
  52. throw(err);
  53. admin = dbAdmin;
  54. done();
  55. });
  56. });
  57. });
  58.  
  59. // Call the actual test suite, pass it the auth credentials.
  60. describe("Test Suite", function() {
  61. it("should run the test suite", function(done) {
  62. // No matter what the timeout is set to it still exceeds it
  63. this.timeout(5000);
  64. test_suite({
  65. email: email,
  66. password: password,
  67. token: token,
  68. admin: admin
  69. }, done);
  70. });
  71. });
  72.  
  73. describe("Clear Admins", function() {
  74. it("should clear the admin table", function(done) {
  75. AdminUser.remove({email: email}, function(err) {
  76. if(err)
  77. throw(err);
  78.  
  79. done();
  80. });
  81. });
  82. });
  83.  
  84. };
  85.  
  86. module.exports = configureAuth;
  87.  
  88. var request = require('supertest');
  89.  
  90. var config = require('../config/config');
  91.  
  92. // Wrapper that creates admin user to allow api calls
  93. var ConfigureAuth = require('./ConfigureAuth');
  94.  
  95.  
  96. // Test data
  97. var templateForm = {...}
  98. var submittedForm = {...}
  99.  
  100. ConfigureAuth(
  101. function(credentials, exit) {
  102.  
  103. var url = "localhost:" + config.port;
  104.  
  105. var templateFormId = null;
  106. describe("Form Templates", function() {
  107. describe('POST /api/form/template', function(){
  108. it('should save the template', function(done){
  109. request(url)
  110. .post('/api/form/template')
  111. .query({email: credentials.email, token: credentials.token})
  112. .send({
  113. _admin_id: credentials.admin._id,
  114. template: templateForm,
  115. })
  116. .end(function(err, res){
  117. templateFormId = res.body._id;
  118. res.body.should.have.property('_admin_id').and.be.equal(''+credentials.admin._id);
  119. res.body.should.have.property('template').and.be.instanceof(Object);
  120. done();
  121. });
  122. });
  123. });
  124.  
  125. describe('GET /api/form/template/:id', function(){
  126. it('Should respond with template data', function(done){
  127. request(url)
  128. .get('/api/form/template/' + templateFormId)
  129. .query({email: credentials.email, token: credentials.token})
  130. .end(function(err, res){
  131. ...
  132. done();
  133. });
  134. });
  135. });
  136.  
  137. describe('GET /api/form/template/company/:id', function(){
  138. it('Should respond with company template data', function(done){
  139. request(url)
  140. .get('/api/form/template/company/' + credentials.admin._id)
  141. .query({email: credentials.email, token: credentials.token})
  142. .end(function(err, res){
  143. ...
  144. done();
  145. });
  146. });
  147. });
  148.  
  149. describe('DELETE /api/form/template/:template_id', function(){
  150. it('Should delete the template data', function(done){
  151. request(url)
  152. .delete('/api/form/template/' + templateFormId)
  153. .query({email: credentials.email, token: credentials.token})
  154. .end(function(err, res){
  155. ...
  156. done();
  157. });
  158. });
  159. });
  160. });
  161.  
  162.  
  163. describe("Submitted Forms", function() {
  164. describe('POST /api/form/patient', function(){
  165. it('should save submitted form', function(done){
  166. request(url)
  167. .post('/api/form/patient')
  168. .query({email: credentials.email, token: credentials.token})
  169. .send({
  170. _admin_id: credentials.admin._id,
  171. form: submittedForm,
  172. firstName: "Jimbo",
  173. lastName: "Cruise",
  174. patientEmail: "jcruise@tomcruise.com",
  175. })
  176. .end(function(err, res){
  177. ...
  178. submittedFormId = res.body._id;
  179. done();
  180. });
  181. });
  182. });
  183.  
  184. describe('GET /api/form/:form_id', function(){
  185. it('should respond with submitted form data', function(done){
  186. request(url)
  187. .get('/api/form/patient/' + submittedFormId)
  188. .query({email: credentials.email, token: credentials.token})
  189. .end(function(err, res){
  190. res.body.should.have.property('_id');
  191.  
  192. ...
  193.  
  194. done();
  195. });
  196. });
  197. });
  198. });
  199.  
  200.  
  201. after(function() {
  202. exit();
  203. });
  204. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement