Skip to content
This repository has been archived by the owner on Jun 10, 2022. It is now read-only.

Commit

Permalink
Fixed Longs that were being implicitly converted to ints in the names…
Browse files Browse the repository at this point in the history
…paces/names endpoint
  • Loading branch information
Vektrat authored Jul 29, 2020
1 parent 9d78ca6 commit 41b5bc9
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
2 changes: 1 addition & 1 deletion rest/src/db/CatapultDb.js
Original file line number Diff line number Diff line change
Expand Up @@ -476,7 +476,7 @@ class CatapultDb {
};

const collection = this.database.collection('transactions');
return collection.aggregate([conditions, grouping])
return collection.aggregate([conditions, grouping], { promoteLongs: false })
.sort({ _id: -1 })
.toArray()
.then(this.sanitizer.deleteIds);
Expand Down
23 changes: 20 additions & 3 deletions rest/test/db/CatapultDb_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -984,9 +984,9 @@ describe('catapult db', () => {
);

const createExpected = (parentId, markerId) => ({
markerId,
markerId: Long.fromNumber(markerId),
markerName: `marker-${markerId}`,
parentMarkerId: parentId
parentMarkerId: Long.fromNumber(parentId)
});

it('returns empty array for unknown ids', () =>
Expand Down Expand Up @@ -1016,9 +1016,26 @@ describe('catapult db', () => {

return assertTransactions(expected, [[20003, 0], [123, 456], [20008, 0]]);
});

it('does not promote MongoDb.Long to regular `number` for small enough numbers and ends up returning Long always', () => {
const dbEntity = {
transactions: [{
_id: test.db.createObjectId(55),
meta: {},
transaction: { id: Long.fromNumber(23), type: 0x12345, parentId: Long.fromNumber(10) }
}]
};
return runDbTest(
dbEntity,
db => db.findNamesByIds([23], 0x12345, { id: 'id', name: 'name', parentId: 'parentId' }),
tuples => {
expect(tuples[0].parentId instanceof Long).to.be.equal(true);
}
);
});
});

describe('queryPagedDocuments 2', () => {
describe('queryPagedDocuments', () => {
describe('calls queryPagedDocumentsWithConditions with', () => {
const sortConditions = { $sort: { _id: 1 } };
const options = { pageSize: 10, pageNumber: 1 };
Expand Down

0 comments on commit 41b5bc9

Please sign in to comment.