Skip to content

Commit

Permalink
Merge pull request #982 from CatalysmsServerManager/development
Browse files Browse the repository at this point in the history
  • Loading branch information
niekcandaele authored Dec 8, 2021
2 parents 936f6a8 + e44462c commit d5e4bbc
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 6 deletions.
10 changes: 9 additions & 1 deletion api/controllers/SdtdServer/available-items.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,14 @@ module.exports = {
`listitems ${inputs.item}`
);

return exits.success(response);
items = response.result
.split('\n')
.map(function(item) {
return item.trim();
}).filter(Boolean)
// Remove the last element, which is the total
.slice(0, -1);

return exits.success(items);
}
};
9 changes: 4 additions & 5 deletions assets/js/sdtdServer/chat.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ class sdtdChat {


start() {

io.socket.on('chatMessage', (chatMessage) => {
if (chatMessage.server.id === this.serverId) {
this.addNewChatMessage(chatMessage);
Expand Down Expand Up @@ -55,12 +54,12 @@ class sdtdChat {
chatMessage.playerName = _.escape(chatMessage.playerName);

if (chatMessage.playerName === 'Server') {
$('.chat-window').append(`<li class=\"chat-message\">[${chatMessage.time}] ${chatMessage.messageText} </li>`);
addMessageToStorage(`[${chatMessage.time}] ${chatMessage.messageText}`, this.serverId);
$('.chat-window').append(`<li class=\"chat-message\">[${new Date().toLocaleTimeString()}] ${chatMessage.messageText} </li>`);
addMessageToStorage(`[${new Date().toLocaleTimeString()}] ${chatMessage.messageText}`, this.serverId);

} else {
$('.chat-window').append(`<li class=\"chat-message\">[${chatMessage.time}] ${chatMessage.playerName}: ${chatMessage.messageText} </li>`);
addMessageToStorage(`[${chatMessage.time}] ${chatMessage.playerName}: ${chatMessage.messageText}`, this.serverId);
$('.chat-window').append(`<li class=\"chat-message\">[${new Date().toLocaleTimeString()}] ${chatMessage.playerName}: ${chatMessage.messageText} </li>`);
addMessageToStorage(`[${new Date().toLocaleTimeString()}] ${chatMessage.playerName}: ${chatMessage.messageText}`, this.serverId);
}
$('.chat-window').scrollTop($('.chat-window')[0].scrollHeight);

Expand Down
40 changes: 40 additions & 0 deletions test/integration/controllers/available-items.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
const supertest = require('supertest');
const { expect } = require('chai');

describe('GET Available items', function () {

it('Should return an array of items', async function () {
sandbox.stub(sails.helpers.sdtdApi,'executeConsoleCommand').resolves({'command':'listitems','parameters':'test','result':' cntBruteStyleTrashCanEmpty\n cntBruteStyleTrashCanFull\n cntBruteStyleTrashCanRandomLootHelper\n cntQuestTestLoot\n TestCubeP\n TestCubeA\n TestCubeC\n TestCubeY\n TestCubeO\n rampCornerCutoutTest\n curve_3x3x1TEST\n turret_3x3TEST\n turret_4x4x6TEST\n elevatorTest\n rampGutterTest\n rampGutterOutsideCornerTest\n cube3mTest\n qtest_nextTraderAdmin\n resourceTestosteroneExtract\n noteTestersDelightAdmin\n noteTestersElectricityAdmin\n bookPistolPeteSteadyHand\nListed 22 matching items.\n'});
const response = await supertest(sails.hooks.http.app).get(`/api/sdtdserver/availableitems?serverId=${sails.testServer.id}&item=*`);
expect(response.statusCode).to.equal(200);
expect(response.body).to.be.an('array');
expect(response.body).to.have.lengthOf(22);
expect(response.body).to.deep.equal([
'cntBruteStyleTrashCanEmpty',
'cntBruteStyleTrashCanFull',
'cntBruteStyleTrashCanRandomLootHelper',
'cntQuestTestLoot',
'TestCubeP',
'TestCubeA',
'TestCubeC',
'TestCubeY',
'TestCubeO',
'rampCornerCutoutTest',
'curve_3x3x1TEST',
'turret_3x3TEST',
'turret_4x4x6TEST',
'elevatorTest',
'rampGutterTest',
'rampGutterOutsideCornerTest',
'cube3mTest',
'qtest_nextTraderAdmin',
'resourceTestosteroneExtract',
'noteTestersDelightAdmin',
'noteTestersElectricityAdmin',
'bookPistolPeteSteadyHand',
]);
});


});

0 comments on commit d5e4bbc

Please sign in to comment.