1+ 'use strict' ;
2+
3+ const expect = require ( 'chai' ) . expect ;
4+ const request = require ( 'superagent' ) ;
5+ const mongoose = require ( 'mongoose' ) ;
6+ const Promise = require ( 'bluebird' ) ;
7+
8+ const User = require ( '../models/user.js' ) ;
9+ const Gallery = require ( '../models/gallery.js' ) ;
10+ const Pic = require ( '../models/pic.js' ) ;
11+
12+ require ( '../server.js' ) ;
13+
14+ const url = `http://localhost:${ process . env . PORT } ` ;
15+
16+ const testUser = {
17+ username : 'testy2' ,
18+ password : 'abc1234' ,
19+ email : 'fake@fake.edu' ,
20+ } ;
21+
22+ const testGallery = {
23+ name : 'testname2' ,
24+ desc : 'testdescription2' ,
25+ } ;
26+
27+ mongoose . Promise = Promise ;
28+
29+ describe . only ( 'Picture routes' , function ( ) {
30+ before ( done => {
31+ new User ( testUser )
32+ . generatePasswordHash ( testUser . password )
33+ . then ( user => user . save ( ) )
34+ . then ( user => {
35+ this . tempUser = user ;
36+ console . log ( 'tempuser' , this . tempUser ) ;
37+ return user . generateToken ( ) ;
38+ } )
39+ . then ( token => {
40+ this . tempToken = token ;
41+ done ( ) ;
42+ } )
43+ . catch ( ( ) => done ( ) ) ;
44+ } ) ;
45+
46+ let tempGallery ;
47+ before ( done => {
48+ testGallery . userId = this . tempUser . _id . toString ( ) ;
49+ new Gallery ( testGallery ) . save ( )
50+ . then ( gallery => {
51+ tempGallery = gallery ;
52+ done ( ) ;
53+ } )
54+ . catch ( ( ) => done ( ) ) ;
55+ } ) ;
56+
57+ console . log ( 'temp gallery' , this . tempGallery ) ;
58+ afterEach ( done => {
59+ Promise . all ( [
60+ User . remove ( { } ) ,
61+ Gallery . remove ( { } ) ,
62+ Pic . remove ( { } ) ,
63+ ] )
64+ . then ( ( ) => done ( ) ) ;
65+ } ) ;
66+
67+ describe ( 'POST test' , function ( ) {
68+ it ( 'should add a new image' , done => {
69+ request . post ( `${ url } /api/gallery/${ tempGallery . _id } /image` )
70+ . set ( 'Content-Type' , 'application/json' )
71+ . set ( { Authorization : `Bearer ${ this . tempToken } ` } )
72+ . field ( 'name' , 'Lake Blanca' )
73+ . field ( 'description' , 'Lake Blanca in the Alpine Lakes Wilderness' )
74+ . attach ( 'image' , `${ __dirname } /assets/Blanca.jpg` )
75+ . end ( ( err , res ) => {
76+ expect ( res . status ) . to . equal ( 200 ) ;
77+ done ( ) ;
78+ } ) ;
79+ } ) ;
80+ } ) ;
81+
82+ describe ( 'DELETE test' , function ( ) {
83+ it ( 'should remove the photo' , done => {
84+ request . delete ( )
85+ done ( ) ;
86+ } ) ;
87+ } ) ;
88+ } ) ;
0 commit comments