diff --git a/server/routes/transferRouter.spec.js b/server/routes/transferRouter.spec.js index 4b701426..e268b921 100644 --- a/server/routes/transferRouter.spec.js +++ b/server/routes/transferRouter.spec.js @@ -279,7 +279,7 @@ describe("transferRouter", () => { }); }); - describe.only("GET /{transfer_id}/tokens", () => { + describe("GET /{transfer_id}/tokens", () => { it("Successfully", async () => { const wallet = new Wallet(1); diff --git a/server/services/TokenService.js b/server/services/TokenService.js index 44d8aeab..8334a779 100644 --- a/server/services/TokenService.js +++ b/server/services/TokenService.js @@ -103,9 +103,12 @@ class TokenService{ const result = await this.transactionRepository.getByFilter({ transfer_id: transferId, }); - return result.map(object => { - return new Token(object, this._session); - }); + const tokens = []; + for(const r of result){ + const token = await this.getById(r.token_id); + tokens.push(token); + } + return tokens; } } diff --git a/server/services/TokenService.spec.js b/server/services/TokenService.spec.js index 1de8444e..b7dcfd25 100644 --- a/server/services/TokenService.spec.js +++ b/server/services/TokenService.spec.js @@ -87,12 +87,19 @@ describe("Token", () => { describe("getTokensByTransferId", () => { it("Successfuly", async () => { - const fn = sinon.stub(TransactionRepository.prototype, "getByFilter").resolves([{id:1}]); + const token = new Token({id:2}); + const transaction = { + id: 1, + token_id: 2, + }; + const fn = sinon.stub(TransactionRepository.prototype, "getByFilter").resolves([transaction]); + const fn2 = sinon.stub(TokenService.prototype, "getById").resolves(token); const tokens = await tokenService.getTokensByTransferId(1); - expect(tokens).lengthOf(1); expect(fn).calledWith({ transfer_id: 1, }) + expect(fn2).calledWith(2); + expect(tokens).lengthOf(1); }); });