Skip to content

Commit

Permalink
Merge 175d033 into b69ff5f
Browse files Browse the repository at this point in the history
  • Loading branch information
niekcandaele committed Jul 2, 2020
2 parents b69ff5f + 175d033 commit cd5022f
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 3 deletions.
6 changes: 3 additions & 3 deletions api/controllers/Player/give-item.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ module.exports = {
cmdToExec = `give ${player.entityId} ${inputs.itemName} ${inputs.amount} ${inputs.quality ? inputs.quality : ''}`;
}

let response = await SdtdApi.executeConsoleCommand({
let response = await sails.helpers.sdtdApi.executeConsoleCommand({
ip: server.ip,
port: server.webPort,
adminUser: server.authName,
Expand All @@ -75,15 +75,15 @@ module.exports = {
}


await SdtdApi.executeConsoleCommand({
await sails.helpers.sdtdApi.executeConsoleCommand({
ip: server.ip,
port: server.webPort,
adminUser: server.authName,
adminToken: server.authToken
}, `pm ${player.steamId} "CSMM - You have received ${inputs.amount} of ${inputs.itemName}"`);

sails.log.info(`API - Player:give-item - giving ${inputs.amount} of ${inputs.itemName} to ${inputs.playerId} with quality: ${inputs.quality}`);

return exits.success();
} catch (error) {
sails.log.error(`API - Player:give-item - ${error}`);
return exits.error(error);
Expand Down
28 changes: 28 additions & 0 deletions test/integration/controllers/give-item.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
const supertest = require('supertest');
const { expect } = require("chai");

describe('/api/player/giveitem', function () {
it('returns OK with correct data', async function () {
sandbox.stub(sails.helpers.sdtdApi, "executeConsoleCommand").callsFake(async () => {
return {
result: "Item given"
}
});
sandbox.stub(sails.helpers.sdtd, "checkCpmVersion").callsFake(async () => 7);

const response = await supertest(sails.hooks.http.app)
.post('/api/player/giveitem')
.send({
playerId: 1,
itemName: "something",
amount: "1"
})

expect(response.statusCode).to.equal(200);
expect(response.body).to.deep.eq({});

})

});


0 comments on commit cd5022f

Please sign in to comment.