Skip to content

Commit

Permalink
fix: wrong doing when get the token info on /transfer/tokens API
Browse files Browse the repository at this point in the history
  • Loading branch information
dadiorchen committed Dec 15, 2020
1 parent 5030d05 commit ca89d4c
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 6 deletions.
2 changes: 1 addition & 1 deletion server/routes/transferRouter.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
9 changes: 6 additions & 3 deletions server/services/TokenService.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

}
Expand Down
11 changes: 9 additions & 2 deletions server/services/TokenService.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
});

Expand Down

0 comments on commit ca89d4c

Please sign in to comment.