forked from ember-fastboot/ember-cli-fastboot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfastboot-location-test.js
173 lines (151 loc) · 5.64 KB
/
fastboot-location-test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
'use strict';
const expect = require('chai').expect;
const RSVP = require('rsvp');
const request = RSVP.denodeify(require('request'));
const setFastbootPkgPath = require('../lib/path/set-fastboot-pkg-path');
const AddonTestApp = require('ember-cli-addon-tests').AddonTestApp;
describe('FastBootLocation', function () {
this.timeout(300000);
let app;
before(function () {
app = new AddonTestApp();
return app
.create('fastboot-location', {
emberVersion: '~3.28.12',
emberDataVersion: '~3.28.12',
})
.then(function () {
app.editPackageJSON((pkg) => {
setFastbootPkgPath(pkg);
delete pkg.devDependencies['ember-fetch'];
delete pkg.devDependencies['ember-welcome-page'];
// needed because @ember-data/store does `FastBoot.require('crypto')`
pkg.fastbootDependencies = ['node-fetch', 'crypto'];
});
return app.run('npm', 'install');
})
.then(function () {
return app.startServer({
command: 'serve',
});
});
});
after(function () {
return app.stopServer();
});
it('should NOT redirect when no transition is called', function () {
return request({
url: 'http://localhost:49741/my-root/test-passed',
followRedirect: false,
headers: {
Accept: 'text/html',
},
}).then(function (response) {
if (response.statusCode === 500) throw new Error(response.body);
expect(response.statusCode).to.equal(200);
expect(response.headers).to.not.include.keys('location');
expect(response.headers).to.include.keys('x-fastboot-path');
expect(response.headers['x-fastboot-path']).to.equal(
'/my-root/test-passed'
);
expect(response.body).to.contain('The Test Passed!');
});
});
it('should NOT redirect when intermediateTransitionTo is called', function () {
return request({
url: 'http://localhost:49741/my-root/redirect-on-intermediate-transition-to',
followRedirect: false,
headers: {
Accept: 'text/html',
},
}).then(function (response) {
if (response.statusCode === 500) throw new Error(response.body);
expect(response.statusCode).to.equal(200);
expect(response.headers).to.not.include.keys('location');
expect(response.headers).to.include.keys('x-fastboot-path');
expect(response.headers['x-fastboot-path']).to.equal(
'/my-root/redirect-on-intermediate-transition-to'
);
expect(response.body).to.not.contain('Welcome to Ember');
expect(response.body).to.not.contain('The Test Passed!');
});
});
it('should redirect when transitionTo is called', function () {
return request({
url: 'http://localhost:49741/my-root/redirect-on-transition-to',
followRedirect: false,
headers: {
Accept: 'text/html',
},
}).then(function (response) {
if (response.statusCode === 500) throw new Error(response.body);
expect(response.statusCode).to.equal(307);
expect(response.headers).to.include.keys(['location', 'x-fastboot-path']);
expect(response.headers.location).to.equal(
'//localhost:49741/my-root/test-passed'
);
expect(response.headers['x-fastboot-path']).to.equal(
'/my-root/test-passed'
);
expect(response.body).to.contain('Redirecting to');
expect(response.body).to.contain('/my-root/test-passed');
});
});
it('should redirect when replaceWith is called', function () {
return request({
url: 'http://localhost:49741/my-root/redirect-on-replace-with',
followRedirect: false,
headers: {
Accept: 'text/html',
},
}).then(function (response) {
if (response.statusCode === 500) throw new Error(response.body);
expect(response.statusCode).to.equal(307);
expect(response.headers).to.include.keys(['location', 'x-fastboot-path']);
expect(response.headers.location).to.equal(
'//localhost:49741/my-root/test-passed'
);
expect(response.headers['x-fastboot-path']).to.equal(
'/my-root/test-passed'
);
expect(response.body).to.contain('Redirecting to');
expect(response.body).to.contain('/my-root/test-passed');
});
});
it('should NOT redirect when transitionTo is called with identical route name', function () {
return request({
url: 'http://localhost:49741/my-root/noop-transition-to',
followRedirect: false,
headers: {
Accept: 'text/html',
},
}).then(function (response) {
if (response.statusCode === 500) throw new Error(response.body);
expect(response.statusCode).to.equal(200);
expect(response.headers).to.not.include.keys('location');
expect(response.headers).to.include.keys('x-fastboot-path');
expect(response.headers['x-fastboot-path']).to.equal(
'/my-root/noop-transition-to'
);
expect(response.body).to.contain('Redirect to self');
});
});
it('should NOT redirect when replaceWith is called with identical route name', function () {
return request({
url: 'http://localhost:49741/my-root/noop-replace-with',
followRedirect: false,
headers: {
Accept: 'text/html',
},
}).then(function (response) {
if (response.statusCode === 500) throw new Error(response.body);
expect(response.statusCode).to.equal(200);
expect(response.headers).to.not.include.keys('location');
expect(response.headers).to.include.keys('x-fastboot-path');
expect(response.headers['x-fastboot-path']).to.equal(
'/my-root/noop-replace-with'
);
expect(response.body).to.contain('Redirect to self');
});
});
});