mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-10-26 16:46:12 +01:00
test: fix x-redirect tests
This commit is contained in:
@@ -942,7 +942,7 @@ describe('Controllers', () => {
|
|||||||
it('should redirect to account page with logged in user', async () => {
|
it('should redirect to account page with logged in user', async () => {
|
||||||
const { response, body } = await request.get(`${nconf.get('url')}/api/login`, { jar });
|
const { response, body } = await request.get(`${nconf.get('url')}/api/login`, { jar });
|
||||||
assert.equal(response.statusCode, 200);
|
assert.equal(response.statusCode, 200);
|
||||||
assert.equal(response.headers['x-redirect'], '/user/foo');
|
assert.equal(response.headers['x-redirect'], encodeURIComponent('/user/foo'));
|
||||||
assert.equal(body, '/user/foo');
|
assert.equal(body, '/user/foo');
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -954,14 +954,14 @@ describe('Controllers', () => {
|
|||||||
it('should redirect to userslug', async () => {
|
it('should redirect to userslug', async () => {
|
||||||
const { response, body } = await request.get(`${nconf.get('url')}/api/uid/${fooUid}`);
|
const { response, body } = await request.get(`${nconf.get('url')}/api/uid/${fooUid}`);
|
||||||
assert.equal(response.statusCode, 200);
|
assert.equal(response.statusCode, 200);
|
||||||
assert.equal(response.headers['x-redirect'], '/user/foo');
|
assert.equal(response.headers['x-redirect'], encodeURIComponent('/user/foo'));
|
||||||
assert.equal(body, '/user/foo');
|
assert.equal(body, '/user/foo');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should redirect to userslug and keep query params', async () => {
|
it('should redirect to userslug and keep query params', async () => {
|
||||||
const { response, body } = await request.get(`${nconf.get('url')}/api/uid/${fooUid}/topics?foo=bar`);
|
const { response, body } = await request.get(`${nconf.get('url')}/api/uid/${fooUid}/topics?foo=bar`);
|
||||||
assert.equal(response.statusCode, 200);
|
assert.equal(response.statusCode, 200);
|
||||||
assert.equal(response.headers['x-redirect'], '/user/foo/topics?foo=bar');
|
assert.equal(response.headers['x-redirect'], encodeURIComponent('/user/foo/topics?foo=bar'));
|
||||||
assert.equal(body, '/user/foo/topics?foo=bar');
|
assert.equal(body, '/user/foo/topics?foo=bar');
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -981,14 +981,14 @@ describe('Controllers', () => {
|
|||||||
it('api should redirect to /user/[userslug]/bookmarks', async () => {
|
it('api should redirect to /user/[userslug]/bookmarks', async () => {
|
||||||
const { response, body } = await request.get(`${nconf.get('url')}/api/me/bookmarks`, { jar });
|
const { response, body } = await request.get(`${nconf.get('url')}/api/me/bookmarks`, { jar });
|
||||||
assert.equal(response.statusCode, 200);
|
assert.equal(response.statusCode, 200);
|
||||||
assert.equal(response.headers['x-redirect'], '/user/foo/bookmarks');
|
assert.equal(response.headers['x-redirect'], encodeURIComponent('/user/foo/bookmarks'));
|
||||||
assert.equal(body, '/user/foo/bookmarks');
|
assert.equal(body, '/user/foo/bookmarks');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('api should redirect to /user/[userslug]/edit/username', async () => {
|
it('api should redirect to /user/[userslug]/edit/username', async () => {
|
||||||
const { response, body } = await request.get(`${nconf.get('url')}/api/me/edit/username`, { jar });
|
const { response, body } = await request.get(`${nconf.get('url')}/api/me/edit/username`, { jar });
|
||||||
assert.equal(response.statusCode, 200);
|
assert.equal(response.statusCode, 200);
|
||||||
assert.equal(response.headers['x-redirect'], '/user/foo/edit/username');
|
assert.equal(response.headers['x-redirect'], encodeURIComponent('/user/foo/edit/username'));
|
||||||
assert.equal(body, '/user/foo/edit/username');
|
assert.equal(body, '/user/foo/edit/username');
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -1387,7 +1387,7 @@ describe('Controllers', () => {
|
|||||||
it('should return correct post path', async () => {
|
it('should return correct post path', async () => {
|
||||||
const { response, body } = await request.get(`${nconf.get('url')}/api/post/${pid}`);
|
const { response, body } = await request.get(`${nconf.get('url')}/api/post/${pid}`);
|
||||||
assert.equal(response.statusCode, 200);
|
assert.equal(response.statusCode, 200);
|
||||||
assert.equal(response.headers['x-redirect'], '/topic/1/test-topic-title');
|
assert.equal(response.headers['x-redirect'], encodeURIComponent('/topic/1/test-topic-title'));
|
||||||
assert.equal(body, '/topic/1/test-topic-title');
|
assert.equal(body, '/topic/1/test-topic-title');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -1500,7 +1500,7 @@ describe('Controllers', () => {
|
|||||||
});
|
});
|
||||||
const { response, body } = await request.get(`${nconf.get('url')}/api/users`);
|
const { response, body } = await request.get(`${nconf.get('url')}/api/users`);
|
||||||
assert.equal(response.statusCode, 200);
|
assert.equal(response.statusCode, 200);
|
||||||
assert.equal(response.headers['x-redirect'], '/api/popular');
|
assert.equal(response.headers['x-redirect'], encodeURIComponent('/api/popular'));
|
||||||
assert(body, '/api/popular');
|
assert(body, '/api/popular');
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -1605,12 +1605,12 @@ describe('Controllers', () => {
|
|||||||
const { cid } = category;
|
const { cid } = category;
|
||||||
|
|
||||||
let result = await request.get(`${nconf.get('url')}/api/category/${category.slug}`, { jar });
|
let result = await request.get(`${nconf.get('url')}/api/category/${category.slug}`, { jar });
|
||||||
assert.equal(result.response.headers['x-redirect'], 'https://nodebb.org');
|
assert.equal(result.response.headers['x-redirect'], encodeURIComponent('https://nodebb.org'));
|
||||||
assert.equal(result.body, 'https://nodebb.org');
|
assert.equal(result.body, 'https://nodebb.org');
|
||||||
await categories.setCategoryField(cid, 'link', '/recent');
|
await categories.setCategoryField(cid, 'link', '/recent');
|
||||||
|
|
||||||
result = await request.get(`${nconf.get('url')}/api/category/${category.slug}`, { jar });
|
result = await request.get(`${nconf.get('url')}/api/category/${category.slug}`, { jar });
|
||||||
assert.equal(result.response.headers['x-redirect'], '/recent');
|
assert.equal(result.response.headers['x-redirect'], encodeURIComponent('/recent'));
|
||||||
assert.equal(result.body, '/recent');
|
assert.equal(result.body, '/recent');
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -1686,7 +1686,7 @@ describe('Controllers', () => {
|
|||||||
it('should redirect if page is out of bounds', async () => {
|
it('should redirect if page is out of bounds', async () => {
|
||||||
const { response, body } = await request.get(`${nconf.get('url')}/api/unread?page=-1`, { jar });
|
const { response, body } = await request.get(`${nconf.get('url')}/api/unread?page=-1`, { jar });
|
||||||
assert.equal(response.statusCode, 200);
|
assert.equal(response.statusCode, 200);
|
||||||
assert.equal(response.headers['x-redirect'], '/unread?page=1');
|
assert.equal(response.headers['x-redirect'], encodeURIComponent('/unread?page=1'));
|
||||||
assert.equal(body, '/unread?page=1');
|
assert.equal(body, '/unread?page=1');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -807,7 +807,7 @@ describe('Messaging Library', () => {
|
|||||||
const { response, body } = await request.get(`${nconf.get('url')}/api/chats`, { jar });
|
const { response, body } = await request.get(`${nconf.get('url')}/api/chats`, { jar });
|
||||||
|
|
||||||
assert.equal(response.statusCode, 200);
|
assert.equal(response.statusCode, 200);
|
||||||
assert.equal(response.headers['x-redirect'], '/user/herp/chats');
|
assert.equal(response.headers['x-redirect'], encodeURIComponent('/user/herp/chats'));
|
||||||
assert.equal(body, '/user/herp/chats');
|
assert.equal(body, '/user/herp/chats');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -1104,7 +1104,7 @@ describe('Topic\'s', () => {
|
|||||||
it('should redirect if post index is out of range', async () => {
|
it('should redirect if post index is out of range', async () => {
|
||||||
const { response, body } = await request.get(`${nconf.get('url')}/api/topic/${topicData.slug}/-1`);
|
const { response, body } = await request.get(`${nconf.get('url')}/api/topic/${topicData.slug}/-1`);
|
||||||
assert.equal(response.statusCode, 200);
|
assert.equal(response.statusCode, 200);
|
||||||
assert.equal(response.headers['x-redirect'], `/topic/${topicData.tid}/topic-for-controller-test`);
|
assert.equal(response.headers['x-redirect'], encodeURIComponent(`/topic/${topicData.tid}/topic-for-controller-test`));
|
||||||
assert.equal(body, `/topic/${topicData.tid}/topic-for-controller-test`);
|
assert.equal(body, `/topic/${topicData.tid}/topic-for-controller-test`);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user