Skip to content

Commit c6cb664

Browse files
committed
Test fuzzysearch integration with new changes in pr 1772 on 7-28-25
1 parent 7e66c94 commit c6cb664

File tree

3 files changed

+35
-11
lines changed

3 files changed

+35
-11
lines changed

api/main_endpoints/routes/Cleezy.js

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ const router = express.Router();
44
const {
55
decodeToken,
66
checkIfTokenSent,
7+
checkIfTokenValid,
78
} = require('../util/token-functions.js');
89
const {
910
OK,
@@ -13,6 +14,7 @@ const {
1314
} = require('../../util/constants').STATUS_CODES;
1415
const logger = require('../../util/logger');
1516
const { Cleezy } = require('../../config/config.json');
17+
const membershipState = require('../../util/constants').MEMBERSHIP_STATE;
1618
const { ENABLED } = Cleezy;
1719

1820
let CLEEZY_URL = process.env.CLEEZY_URL
@@ -97,14 +99,19 @@ router.post('/deleteUrl', async (req, res) => {
9799
});
98100
});
99101

102+
const searchCleezyUrls = async (req) => {
103+
if(!ENABLED || !req.body.query) {
104+
return { status: OK, data: [] };
105+
}
100106

101-
const searchCleezyUrls = async (query) => {
102-
if(!ENABLED || !query) {
103-
return;
107+
if (!checkIfTokenSent(req)) {
108+
return { status: FORBIDDEN, data: [] };
109+
} else if (!checkIfTokenValid(req, membershipState.OFFICER)) {
110+
return { status: UNAUTHORIZED, data: [] };
104111
}
105112

106113
try {
107-
const cleezyQuery = query.replace(/[^a-zA-Z0-9]/g, '');
114+
const cleezyQuery = req.body.query.replace(/[^a-zA-Z0-9]/g, '');
108115
const cleezyRes = await axios.get(CLEEZY_URL + '/list', {
109116
params: {
110117
search: cleezyQuery
@@ -117,9 +124,10 @@ const searchCleezyUrls = async (query) => {
117124
return { ...e, link: u.href };
118125
});
119126

120-
return cleezyData;
127+
return { status: OK, data: cleezyData };
121128
} catch (err) {
122129
logger.error('cleezy search urls had an error', err);
130+
return { status: SERVER_ERROR, data: [] };
123131
}
124132
};
125133

api/main_endpoints/routes/ShortcutSearch.js

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,14 +102,29 @@ router.post('/', async function(req, res) {
102102
// Short circuit if cleezy is disabled
103103
if(!ENABLED) {
104104
return res.status(OK).json({
105-
items: {users: sortUsers, cleezyData: []},
105+
items: { users: sortUsers, cleezyData: [] },
106106
disabled: true
107107
});
108108
}
109109

110-
const cleezyData = await cleezy.searchCleezyUrls(req.body.query);
110+
const cleezyRes = await cleezy.searchCleezyUrls(req);
111+
if (cleezyRes.status !== OK) {
112+
logger.warn('Cleezy search failed', {
113+
status: cleezyRes.status
114+
});
115+
116+
return res.status(OK).send({
117+
cleezyStatus: cleezyRes.status,
118+
items: { users: sortUsers }
119+
});
120+
}
111121

112-
res.status(OK).send({ items: {users: sortUsers, cleezyData} });
122+
return res.status(OK).send({
123+
items: {
124+
users: sortUsers,
125+
cleezyData: cleezyRes.data,
126+
}
127+
});
113128
} catch (error) {
114129
logger.error('/shortcutsearch encountered an error:', { error, query: req.body.query });
115130
if (error.response && error.response.data) {

test/api/User.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ chai.use(chaiHttp);
5252

5353
// Our parent block
5454
describe('User', () => {
55-
before(async () => {
55+
before(done => {
5656
initializeTokenMock();
5757
initializeDiscordAPIMock();
5858
app = tools.initializeServer([
@@ -61,15 +61,16 @@ describe('User', () => {
6161
]);
6262
test = new SceApiTester(app);
6363
// Before each test we empty the database
64-
await tools.emptySchema(User);
64+
tools.emptySchema(User);
6565
const testUser = new User({
6666
6767
password: 'Passw0rd',
6868
firstName: 'first-name',
6969
lastName: 'last-name',
7070
major: 'Computer Science',
7171
});
72-
await testUser.save();
72+
testUser.save();
73+
done();
7374
});
7475

7576
after(done => {

0 commit comments

Comments
 (0)