Skip to content

Commit

Permalink
refactoring transfer to async
Browse files Browse the repository at this point in the history
  • Loading branch information
suculent committed Nov 15, 2023
1 parent cf0f422 commit 499a329
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 9 deletions.
4 changes: 2 additions & 2 deletions lib/router.transfer.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ module.exports = function (app) {
}
}

function requestTransfer(req, res) {
async function requestTransfer(req, res) {
if (!Util.validateSession(req)) return res.status(401).end();
let owner = sanitka.owner(req.session.owner);
transfer.request(owner, req.body, (success, response) => {
await transfer.request(owner, req.body, (success, response) => {
transferResultRedirect(success, res, response);
});
}
Expand Down
5 changes: 3 additions & 2 deletions lib/thinx/transfer.js
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ module.exports = class Transfer {

sendRecipientTransferEmail(body, transfer_uuid) {

if (!Util.isDefined(body.udids)) { console.log("[error] [sendRecipientTransferEmail] missing body.udids"); return }
if (!Util.isDefined(body.udids)) { console.log("[error] [sendRecipientTransferEmail] missing body.udids"); return; }

var htmlDeviceList = "<p><ul>";
for (var dindex in body.udids) {
Expand Down Expand Up @@ -320,7 +320,8 @@ module.exports = class Transfer {
this.sendMail(recipientTransferEmail, "recipient_transfer", () => { /* nop */ });
}

request(owner, body, callback) {
// TODO: refactor from callback to promise?
async request(owner, body, callback) {

// body should look like { "to":"some@email.com", "udids" : [ "some-udid", "another-udid" ] }

Expand Down
10 changes: 5 additions & 5 deletions spec/jasmine/TransferSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ describe("Transfer", function () {
console.log(`🚸 [chai] <<< completed Transfer spec`);
});

it("(00) should be able to initiate device transfer, decline and accept another one", function (done) {
it("(00) should be able to initiate device transfer, decline and accept another one", async function (done) {

let accepted = false;

Expand All @@ -55,7 +55,7 @@ describe("Transfer", function () {
var owner = envi.oid;

// TODO: Turn this into async
transfer.request(owner, body, (t_success, response) => {
await transfer.request(owner, body, (t_success, response) => {
expect(t_success).to.equal(true);
expect(response).to.be.a('string');
const tbody = {
Expand All @@ -64,14 +64,14 @@ describe("Transfer", function () {
};

// 00-02 Decline
transfer.decline(tbody, (d_success, d_response) => {
transfer.decline(tbody, async (d_success, d_response) => {
expect(d_success).to.equal(true);
expect(d_response).to.be.a('string');

// TODO: Turn this into async
transfer.request(owner, body, (b_success, b_response) => {
await transfer.request(owner, body, (b_success, b_response) => {
expect(b_success).to.equal(true);
expect(b_response).to.be.a('string'); // transfer_requested
expect(b_response).to.be.a('string'); // transfer_requested

// 00-04 Accept
var transfer_body = {
Expand Down

0 comments on commit 499a329

Please sign in to comment.