|
| 1 | +var chai = require('chai'); |
| 2 | +var expect = chai.expect; |
| 3 | +var RSVP = require('rsvp'); |
| 4 | +var AddonTestApp = require('ember-cli-addon-tests').AddonTestApp; |
| 5 | +var request = require('request'); |
| 6 | +var get = RSVP.denodeify(request); |
| 7 | + |
| 8 | +describe('FastBootLocation', function () { |
| 9 | + this.timeout(300000); |
| 10 | + |
| 11 | + before(function () { |
| 12 | + app = new AddonTestApp(); |
| 13 | + |
| 14 | + return app.create('fastboot-location') |
| 15 | + .then(function () { |
| 16 | + return app.startServer({ |
| 17 | + command: 'fastboot', |
| 18 | + additionalArguments: ['--serve-assets'] |
| 19 | + }); |
| 20 | + }); |
| 21 | + }); |
| 22 | + |
| 23 | + after(function () { |
| 24 | + return app.stopServer(); |
| 25 | + }); |
| 26 | + |
| 27 | + it('should NOT redirect when no transition is called', function () { |
| 28 | + return get({ |
| 29 | + url: 'http://localhost:49741/test-passed', |
| 30 | + followRedirect: false |
| 31 | + }) |
| 32 | + .then(function (response) { |
| 33 | + if (response.statusCode === 500) throw new Error (response.body); |
| 34 | + expect(response.statusCode).to.equal(200); |
| 35 | + |
| 36 | + expect(response.headers).to.not.include.keys('location'); |
| 37 | + expect(response.headers).to.include.keys('x-fastboot-path'); |
| 38 | + expect(response.headers['x-fastboot-path']).to.equal('/test-passed'); |
| 39 | + |
| 40 | + expect(response.body).to.contain('The Test Passed!'); |
| 41 | + }); |
| 42 | + }); |
| 43 | + |
| 44 | + it.skip('should NOT redirect when intermediateTransitionTo is called', function () { |
| 45 | + return get({ |
| 46 | + url: 'http://localhost:49741/redirect-on-intermediate-transition-to', |
| 47 | + followRedirect: false |
| 48 | + }) |
| 49 | + .then(function (response) { |
| 50 | + if (response.statusCode === 500) throw new Error (response.body); |
| 51 | + expect(response.statusCode).to.equal(200); |
| 52 | + |
| 53 | + expect(response.headers).to.not.include.keys('location'); |
| 54 | + expect(response.headers).to.include.keys('x-fastboot-path'); |
| 55 | + expect(response.headers['x-fastboot-path']).to.equal('/redirect-on-intermediate-transition-to'); |
| 56 | + |
| 57 | + expect(response.body).to.not.contain('Welcome to Ember'); |
| 58 | + expect(response.body).to.not.contain('The Test Passed!'); |
| 59 | + }); |
| 60 | + }); |
| 61 | + |
| 62 | + it('should redirect when transitionTo is called', function () { |
| 63 | + return get({ |
| 64 | + url: 'http://localhost:49741/redirect-on-transition-to', |
| 65 | + followRedirect: false |
| 66 | + }) |
| 67 | + .then(function (response) { |
| 68 | + if (response.statusCode === 500) throw new Error (response.body); |
| 69 | + expect(response.statusCode).to.equal(307); |
| 70 | + |
| 71 | + expect(response.headers).to.include.keys([ |
| 72 | + 'location', |
| 73 | + 'x-fastboot-path' |
| 74 | + ]); |
| 75 | + expect(response.headers.location).to.equal('http://localhost:49741/test-passed'); |
| 76 | + expect(response.body).to.contain('Redirecting to'); |
| 77 | + expect(response.body).to.contain('/test-passed'); |
| 78 | + }); |
| 79 | + }); |
| 80 | + |
| 81 | + it('should redirect when replaceWith is called', function () { |
| 82 | + return get({ |
| 83 | + url: 'http://localhost:49741/redirect-on-replace-with', |
| 84 | + followRedirect: false |
| 85 | + }) |
| 86 | + .then(function (response) { |
| 87 | + if (response.statusCode === 500) throw new Error (response.body); |
| 88 | + expect(response.statusCode).to.equal(307); |
| 89 | + |
| 90 | + expect(response.headers).to.include.keys([ |
| 91 | + 'location', |
| 92 | + 'x-fastboot-path' |
| 93 | + ]); |
| 94 | + expect(response.headers.location).to.equal('http://localhost:49741/test-passed'); |
| 95 | + expect(response.body).to.contain('Redirecting to'); |
| 96 | + expect(response.body).to.contain('/test-passed'); |
| 97 | + }); |
| 98 | + }); |
| 99 | +}); |
0 commit comments