@@ -5,6 +5,7 @@ var path = require('path');
55var assert = require ( 'assert' ) ;
66var async = require ( 'async' ) ;
77var fs = require ( 'fs' ) ;
8+ var moment = require ( 'moment' ) ;
89var request = require ( 'supertest' ) ;
910var nock = require ( 'nock' ) ;
1011var zlib = require ( 'zlib' ) ;
@@ -24,12 +25,7 @@ describe( 'Solidus', function(){
2425
2526 var solidus_server ;
2627
27- beforeEach ( function ( done ) {
28- process . chdir ( site1_path ) ;
29- solidus_server = solidus . start ( {
30- log_level : 0 ,
31- port : 9009
32- } ) ;
28+ before ( function ( done ) {
3329 // mock http endpoints for resources
3430 nock ( 'https://solid.us' ) . get ( '/basic/1' ) . reply ( 200 , { test : true } ) ;
3531 nock ( 'https://solid.us' ) . get ( '/basic/2' ) . reply ( 200 , { test : true } ) ;
@@ -47,34 +43,62 @@ describe( 'Solidus', function(){
4743 nock ( 'https://solid.us' ) . get ( '/resource/options/dynamic/query?test=' ) . reply ( 200 , { test : false } ) ;
4844 nock ( 'https://solid.us' ) . get ( '/resource/options/double/dynamic/query?test2=&test=' ) . reply ( 200 , { test : false } ) ;
4945
50- async . parallel (
51- [
52- // compressed resources
53- function ( callback ) {
54- zlib . gzip ( '{"test":true}' , function ( _ , result ) {
55- nock ( 'https://solid.us' ) . get ( '/compressed/gzip' ) . reply ( 200 , result , { 'Content-Encoding' : 'gzip' } ) ;
56- callback ( ) ;
57- } ) ;
58- } ,
59- function ( callback ) {
60- zlib . deflate ( '{"test":true}' , function ( _ , result ) {
61- nock ( 'https://solid.us' ) . get ( '/compressed/deflate' ) . reply ( 200 , result , { 'Content-Encoding' : 'deflate' } ) ;
62- callback ( ) ;
63- } ) ;
64- } ,
65- // hack that will work until .start callback is complete
66- function ( callback ) {
67- solidus_server . on ( 'ready' , callback ) ;
68- }
69- ] ,
70- function ( ) {
71- done ( ) ;
46+ async . parallel ( [
47+ // compressed resources
48+ function ( callback ) {
49+ zlib . gzip ( '{"test":true}' , function ( _ , result ) {
50+ nock ( 'https://solid.us' ) . get ( '/compressed/gzip' ) . reply ( 200 , result , { 'Content-Encoding' : 'gzip' } ) ;
51+ callback ( ) ;
52+ } ) ;
53+ } ,
54+ function ( callback ) {
55+ zlib . deflate ( '{"test":true}' , function ( _ , result ) {
56+ nock ( 'https://solid.us' ) . get ( '/compressed/deflate' ) . reply ( 200 , result , { 'Content-Encoding' : 'deflate' } ) ;
57+ callback ( ) ;
58+ } ) ;
7259 }
73- ) ;
60+ ] ,
61+ function ( ) {
62+ done ( ) ;
63+ } ) ;
64+ } ) ;
65+
66+ var original_redirects = [ ] ;
67+
68+ beforeEach ( function ( done ) {
69+ process . chdir ( site1_path ) ;
70+ // Generate time-based redirects
71+ // These are used to ensure that temporary redirects are properly checked
72+ original_redirects = fs . readFileSync ( 'redirects.json' , DEFAULT_ENCODING ) ;
73+ var original_redirects_arr = JSON . parse ( original_redirects ) ;
74+ var redirect_date_format = 'YYYY-MM-DD HH:mm:ss' ;
75+ var temporal_redirects = [ {
76+ start : moment ( ) . add ( 's' , 5 ) . format ( redirect_date_format ) ,
77+ from : '/future-redirect' ,
78+ to : '/'
79+ } , {
80+ start : moment ( ) . subtract ( 's' , 5 ) . format ( redirect_date_format ) ,
81+ end : moment ( ) . add ( 's' , 5 ) . format ( redirect_date_format ) ,
82+ from : '/current-redirect' ,
83+ to : '/'
84+ } , {
85+ start : moment ( ) . subtract ( 's' , 10 ) . format ( redirect_date_format ) ,
86+ end : moment ( ) . subtract ( 's' , 5 ) . format ( redirect_date_format ) ,
87+ from : '/past-redirect' ,
88+ to : '/'
89+ } ] ;
90+ var combined_redirects = JSON . stringify ( original_redirects_arr . concat ( temporal_redirects ) ) ;
91+ fs . writeFileSync ( 'redirects.json' , combined_redirects , DEFAULT_ENCODING ) ;
92+ solidus_server = solidus . start ( {
93+ log_level : 0 ,
94+ port : 9009
95+ } ) ;
96+ solidus_server . on ( 'ready' , done ) ;
7497 } ) ;
7598
7699 afterEach ( function ( ) {
77100 solidus_server . stop ( ) ;
101+ fs . writeFileSync ( 'redirects.json' , original_redirects , DEFAULT_ENCODING ) ;
78102 process . chdir ( original_path ) ;
79103 } ) ;
80104
@@ -290,6 +314,15 @@ describe( 'Solidus', function(){
290314 } ,
291315 function ( callback ) {
292316 s_request . get ( '/redirect5' ) . expect ( 301 , callback ) ;
317+ } ,
318+ function ( callback ) {
319+ s_request . get ( '/past-redirect' ) . expect ( 404 , callback ) ;
320+ } ,
321+ function ( callback ) {
322+ s_request . get ( '/current-redirect' ) . expect ( 302 , callback ) ;
323+ } ,
324+ function ( callback ) {
325+ s_request . get ( '/future-redirect' ) . expect ( 404 , callback ) ;
293326 }
294327 ] , function ( err , results ) {
295328 if ( err ) throw err ;
0 commit comments