Skip to content

Commit

Permalink
fix: tests
Browse files Browse the repository at this point in the history
  • Loading branch information
barisusakli committed Oct 14, 2020
1 parent dd7424e commit a411df1
Show file tree
Hide file tree
Showing 16 changed files with 18 additions and 195 deletions.
18 changes: 0 additions & 18 deletions public/openapi/read.yaml
Expand Up @@ -79,24 +79,6 @@ paths:
$ref: 'read/admin/manage/tags.yaml'
/api/admin/manage/users:
$ref: 'read/admin/manage/users.yaml'
/api/admin/manage/users/search:
$ref: 'read/admin/manage/users/search.yaml'
/api/admin/manage/users/latest:
$ref: 'read/admin/manage/users/latest.yaml'
/api/admin/manage/users/not-validated:
$ref: 'read/admin/manage/users/not-validated.yaml'
/api/admin/manage/users/no-posts:
$ref: 'read/admin/manage/users/no-posts.yaml'
/api/admin/manage/users/top-posters:
$ref: 'read/admin/manage/users/top-posters.yaml'
/api/admin/manage/users/most-reputation:
$ref: 'read/admin/manage/users/most-reputation.yaml'
/api/admin/manage/users/inactive:
$ref: 'read/admin/manage/users/inactive.yaml'
/api/admin/manage/users/flagged:
$ref: 'read/admin/manage/users/flagged.yaml'
/api/admin/manage/users/banned:
$ref: 'read/admin/manage/users/banned.yaml'
/api/admin/manage/registration:
$ref: 'read/admin/manage/registration.yaml'
/api/admin/manage/admins-mods:
Expand Down
2 changes: 2 additions & 0 deletions public/openapi/read/admin/manage/privileges/cid.yaml
Expand Up @@ -79,6 +79,8 @@ get:
description: Each privilege will have a key in this object
isPrivate:
type: boolean
isSystem:
type: boolean
columnCountUser:
type: number
columnCountUserOther:
Expand Down
8 changes: 4 additions & 4 deletions public/openapi/read/admin/manage/users.yaml
Expand Up @@ -21,12 +21,12 @@ get:
type: number
resultsPerPage:
type: number
latest:
reverse:
type: boolean
search_display:
sortBy:
type: string
requireEmailConfirmation:
type: number
sort_online:
type: boolean
inviteOnly:
type: boolean
adminInviteOnly:
Expand Down
7 changes: 0 additions & 7 deletions public/openapi/read/admin/manage/users/banned.yaml

This file was deleted.

7 changes: 0 additions & 7 deletions public/openapi/read/admin/manage/users/flagged.yaml

This file was deleted.

7 changes: 0 additions & 7 deletions public/openapi/read/admin/manage/users/inactive.yaml

This file was deleted.

7 changes: 0 additions & 7 deletions public/openapi/read/admin/manage/users/latest.yaml

This file was deleted.

7 changes: 0 additions & 7 deletions public/openapi/read/admin/manage/users/most-reputation.yaml

This file was deleted.

7 changes: 0 additions & 7 deletions public/openapi/read/admin/manage/users/no-posts.yaml

This file was deleted.

7 changes: 0 additions & 7 deletions public/openapi/read/admin/manage/users/not-validated.yaml

This file was deleted.

39 changes: 0 additions & 39 deletions public/openapi/read/admin/manage/users/search.yaml

This file was deleted.

7 changes: 0 additions & 7 deletions public/openapi/read/admin/manage/users/top-posters.yaml

This file was deleted.

8 changes: 5 additions & 3 deletions src/controllers/admin/users.js
Expand Up @@ -36,7 +36,7 @@ async function getUsers(req, res) {
resultsPerPage = 50;
}
let sortBy = validator.escape(req.query.sortBy || '');
const filterBy = Array.isArray(req.query.filters) ? req.query.filters : [req.query.filters];
const filterBy = Array.isArray(req.query.filters || []) ? (req.query.filters || []) : [req.query.filters];
const start = Math.max(0, page - 1) * resultsPerPage;
const stop = start + resultsPerPage - 1;

Expand Down Expand Up @@ -230,8 +230,10 @@ function render(req, res, data) {
data.inviteOnly = registrationType === 'invite-only' || registrationType === 'admin-invite-only';
data.adminInviteOnly = registrationType === 'admin-invite-only';
data['sort_' + data.sortBy] = true;
data['searchBy_' + validator.escape(String(req.query.searchBy))] = true;
const filterBy = Array.isArray(req.query.filters) ? req.query.filters : [req.query.filters];
if (req.query.searchBy) {
data['searchBy_' + validator.escape(String(req.query.searchBy))] = true;
}
const filterBy = Array.isArray(req.query.filters || []) ? (req.query.filters || []) : [req.query.filters];
filterBy.forEach(function (filter) {
data['filterBy_' + validator.escape(String(filter))] = true;
});
Expand Down
5 changes: 4 additions & 1 deletion src/groups/join.js
Expand Up @@ -90,7 +90,10 @@ module.exports = function (Groups) {
}

async function setGroupTitleIfNotSet(groupNames, uid) {
groupNames = groupNames.filter(groupName => groupName !== 'registered-users' && !Groups.isPrivilegeGroup(groupName));
const ignore = ['registered-users', 'verified-users', 'unverified-users'];
groupNames = groupNames.filter(
groupName => !ignore.includes(groupName) && !Groups.isPrivilegeGroup(groupName)
);
if (!groupNames.length) {
return;
}
Expand Down
72 changes: 0 additions & 72 deletions test/controllers-admin.js
Expand Up @@ -219,78 +219,6 @@ describe('Admin Controllers', function () {
});
});

it('should load /admin/manage/users/search', function (done) {
request(nconf.get('url') + '/api/admin/manage/users/search', { jar: jar, json: true }, function (err, res, body) {
assert.ifError(err);
assert.equal(res.statusCode, 200);
assert(body.users);
done();
});
});

it('should load /admin/manage/users/not-validated', function (done) {
request(nconf.get('url') + '/api/admin/manage/users/not-validated', { jar: jar, json: true }, function (err, res, body) {
assert.ifError(err);
assert.equal(res.statusCode, 200);
assert(body);
done();
});
});

it('should load /admin/manage/users/no-posts', function (done) {
request(nconf.get('url') + '/api/admin/manage/users/no-posts', { jar: jar, json: true }, function (err, res, body) {
assert.ifError(err);
assert.equal(res.statusCode, 200);
assert(body);
done();
});
});

it('should load /admin/manage/users/top-posters', function (done) {
request(nconf.get('url') + '/api/admin/manage/users/top-posters', { jar: jar, json: true }, function (err, res, body) {
assert.ifError(err);
assert.equal(res.statusCode, 200);
assert(body);
done();
});
});

it('should load /admin/manage/users/most-reputation', function (done) {
request(nconf.get('url') + '/api/admin/manage/users/most-reputation', { jar: jar, json: true }, function (err, res, body) {
assert.ifError(err);
assert.equal(res.statusCode, 200);
assert(body);
done();
});
});

it('should load /admin/manage/users/inactive', function (done) {
request(nconf.get('url') + '/api/admin/manage/users/inactive', { jar: jar, json: true }, function (err, res, body) {
assert.ifError(err);
assert.equal(res.statusCode, 200);
assert(body);
done();
});
});

it('should load /admin/manage/users/flagged', function (done) {
request(nconf.get('url') + '/api/admin/manage/users/flagged', { jar: jar, json: true }, function (err, res, body) {
assert.ifError(err);
assert.equal(res.statusCode, 200);
assert(body);
done();
});
});

it('should load /admin/manage/users/banned', function (done) {
request(nconf.get('url') + '/api/admin/manage/users/banned', { jar: jar, json: true }, function (err, res, body) {
assert.ifError(err);
assert.equal(res.statusCode, 200);
assert(body);
done();
});
});

it('should load /admin/manage/registration', function (done) {
request(nconf.get('url') + '/api/admin/manage/registration', { jar: jar, json: true }, function (err, res, body) {
assert.ifError(err);
Expand Down
5 changes: 3 additions & 2 deletions test/controllers.js
Expand Up @@ -661,7 +661,7 @@ describe('Controllers', function () {
});

it('should error if guests do not have search privilege', function (done) {
request(nconf.get('url') + '/api/users?term=bar&section=sort-posts', { json: true }, function (err, res, body) {
request(nconf.get('url') + '/api/users?query=bar&section=sort-posts', { json: true }, function (err, res, body) {
assert.ifError(err);
assert.equal(res.statusCode, 500);
assert(body);
Expand All @@ -673,7 +673,7 @@ describe('Controllers', function () {
it('should load users search page', function (done) {
privileges.global.give(['groups:search:users'], 'guests', function (err) {
assert.ifError(err);
request(nconf.get('url') + '/users?term=bar&section=sort-posts', function (err, res, body) {
request(nconf.get('url') + '/users?query=bar&section=sort-posts', function (err, res, body) {
assert.ifError(err);
assert.equal(res.statusCode, 200);
assert(body);
Expand Down Expand Up @@ -1509,6 +1509,7 @@ describe('Controllers', function () {
assert.ifError(err);
request(nconf.get('url') + '/api/user/groupie', { json: true }, function (err, res, body) {
assert.ifError(err);
console.log(body);
assert.equal(res.statusCode, 200);
assert(Array.isArray(body.selectedGroup));
assert.equal(body.selectedGroup[0].name, 'selectedGroup');
Expand Down

0 comments on commit a411df1

Please sign in to comment.