Skip to content

Commit b80440a

Browse files
committed
test: fix x-redirect tests
1 parent 526a952 commit b80440a

File tree

3 files changed

+12
-12
lines changed

3 files changed

+12
-12
lines changed

test/controllers.js

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -942,7 +942,7 @@ describe('Controllers', () => {
942942
it('should redirect to account page with logged in user', async () => {
943943
const { response, body } = await request.get(`${nconf.get('url')}/api/login`, { jar });
944944
assert.equal(response.statusCode, 200);
945-
assert.equal(response.headers['x-redirect'], '/user/foo');
945+
assert.equal(response.headers['x-redirect'], encodeURIComponent('/user/foo'));
946946
assert.equal(body, '/user/foo');
947947
});
948948

@@ -954,14 +954,14 @@ describe('Controllers', () => {
954954
it('should redirect to userslug', async () => {
955955
const { response, body } = await request.get(`${nconf.get('url')}/api/uid/${fooUid}`);
956956
assert.equal(response.statusCode, 200);
957-
assert.equal(response.headers['x-redirect'], '/user/foo');
957+
assert.equal(response.headers['x-redirect'], encodeURIComponent('/user/foo'));
958958
assert.equal(body, '/user/foo');
959959
});
960960

961961
it('should redirect to userslug and keep query params', async () => {
962962
const { response, body } = await request.get(`${nconf.get('url')}/api/uid/${fooUid}/topics?foo=bar`);
963963
assert.equal(response.statusCode, 200);
964-
assert.equal(response.headers['x-redirect'], '/user/foo/topics?foo=bar');
964+
assert.equal(response.headers['x-redirect'], encodeURIComponent('/user/foo/topics?foo=bar'));
965965
assert.equal(body, '/user/foo/topics?foo=bar');
966966
});
967967

@@ -981,14 +981,14 @@ describe('Controllers', () => {
981981
it('api should redirect to /user/[userslug]/bookmarks', async () => {
982982
const { response, body } = await request.get(`${nconf.get('url')}/api/me/bookmarks`, { jar });
983983
assert.equal(response.statusCode, 200);
984-
assert.equal(response.headers['x-redirect'], '/user/foo/bookmarks');
984+
assert.equal(response.headers['x-redirect'], encodeURIComponent('/user/foo/bookmarks'));
985985
assert.equal(body, '/user/foo/bookmarks');
986986
});
987987

988988
it('api should redirect to /user/[userslug]/edit/username', async () => {
989989
const { response, body } = await request.get(`${nconf.get('url')}/api/me/edit/username`, { jar });
990990
assert.equal(response.statusCode, 200);
991-
assert.equal(response.headers['x-redirect'], '/user/foo/edit/username');
991+
assert.equal(response.headers['x-redirect'], encodeURIComponent('/user/foo/edit/username'));
992992
assert.equal(body, '/user/foo/edit/username');
993993
});
994994

@@ -1387,7 +1387,7 @@ describe('Controllers', () => {
13871387
it('should return correct post path', async () => {
13881388
const { response, body } = await request.get(`${nconf.get('url')}/api/post/${pid}`);
13891389
assert.equal(response.statusCode, 200);
1390-
assert.equal(response.headers['x-redirect'], '/topic/1/test-topic-title');
1390+
assert.equal(response.headers['x-redirect'], encodeURIComponent('/topic/1/test-topic-title'));
13911391
assert.equal(body, '/topic/1/test-topic-title');
13921392
});
13931393
});
@@ -1500,7 +1500,7 @@ describe('Controllers', () => {
15001500
});
15011501
const { response, body } = await request.get(`${nconf.get('url')}/api/users`);
15021502
assert.equal(response.statusCode, 200);
1503-
assert.equal(response.headers['x-redirect'], '/api/popular');
1503+
assert.equal(response.headers['x-redirect'], encodeURIComponent('/api/popular'));
15041504
assert(body, '/api/popular');
15051505
});
15061506

@@ -1605,12 +1605,12 @@ describe('Controllers', () => {
16051605
const { cid } = category;
16061606

16071607
let result = await request.get(`${nconf.get('url')}/api/category/${category.slug}`, { jar });
1608-
assert.equal(result.response.headers['x-redirect'], 'https://nodebb.org');
1608+
assert.equal(result.response.headers['x-redirect'], encodeURIComponent('https://nodebb.org'));
16091609
assert.equal(result.body, 'https://nodebb.org');
16101610
await categories.setCategoryField(cid, 'link', '/recent');
16111611

16121612
result = await request.get(`${nconf.get('url')}/api/category/${category.slug}`, { jar });
1613-
assert.equal(result.response.headers['x-redirect'], '/recent');
1613+
assert.equal(result.response.headers['x-redirect'], encodeURIComponent('/recent'));
16141614
assert.equal(result.body, '/recent');
16151615
});
16161616

@@ -1686,7 +1686,7 @@ describe('Controllers', () => {
16861686
it('should redirect if page is out of bounds', async () => {
16871687
const { response, body } = await request.get(`${nconf.get('url')}/api/unread?page=-1`, { jar });
16881688
assert.equal(response.statusCode, 200);
1689-
assert.equal(response.headers['x-redirect'], '/unread?page=1');
1689+
assert.equal(response.headers['x-redirect'], encodeURIComponent('/unread?page=1'));
16901690
assert.equal(body, '/unread?page=1');
16911691
});
16921692
});

test/messaging.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -807,7 +807,7 @@ describe('Messaging Library', () => {
807807
const { response, body } = await request.get(`${nconf.get('url')}/api/chats`, { jar });
808808

809809
assert.equal(response.statusCode, 200);
810-
assert.equal(response.headers['x-redirect'], '/user/herp/chats');
810+
assert.equal(response.headers['x-redirect'], encodeURIComponent('/user/herp/chats'));
811811
assert.equal(body, '/user/herp/chats');
812812
});
813813

test/topics.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1104,7 +1104,7 @@ describe('Topic\'s', () => {
11041104
it('should redirect if post index is out of range', async () => {
11051105
const { response, body } = await request.get(`${nconf.get('url')}/api/topic/${topicData.slug}/-1`);
11061106
assert.equal(response.statusCode, 200);
1107-
assert.equal(response.headers['x-redirect'], `/topic/${topicData.tid}/topic-for-controller-test`);
1107+
assert.equal(response.headers['x-redirect'], encodeURIComponent(`/topic/${topicData.tid}/topic-for-controller-test`));
11081108
assert.equal(body, `/topic/${topicData.tid}/topic-for-controller-test`);
11091109
});
11101110

0 commit comments

Comments
 (0)