forked from dynamodb-toolbox/dynamodb-toolbox
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(format-item): resolve wrap number issues (dynamodb-toolbox#590)
Co-authored-by: Adam McCarthy <[email protected]>
- Loading branch information
1 parent
a59efdf
commit 90f7013
Showing
3 changed files
with
121 additions
and
81 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,6 @@ import { DocumentClientWithWrappedNumbers } from './bootstrap.test' | |
|
||
import Table from '../classes/Table' | ||
import Entity from '../classes/Entity' | ||
import { toDynamoBigInt } from '../lib/utils' | ||
import { unmarshall } from '@aws-sdk/util-dynamodb' | ||
|
||
const TestTable = new Table({ | ||
|
@@ -206,7 +205,8 @@ describe('parse', () => { | |
|
||
it('parses wrapped numbers', () => { | ||
const wrap = (value: number) => | ||
unmarshall({ valueToUnmarshall: {N: value.toString()} }, { wrapNumbers: true }).valueToUnmarshall.value | ||
unmarshall({ valueToUnmarshall: { N: value.toString() } }, { wrapNumbers: true }) | ||
.valueToUnmarshall.value | ||
|
||
const item = TestEntity.parse({ | ||
pk: '[email protected]', | ||
|
@@ -226,35 +226,39 @@ describe('parse', () => { | |
const item = TestEntity.parse({ | ||
pk: '[email protected]', | ||
sk: 'bigint', | ||
test_bigint: toDynamoBigInt(BigInt('90071992547409911234')), | ||
test_bigint: { value: '99999999999999999999999999999999999999' }, | ||
test_bigint_coerce: '12345' | ||
}) | ||
expect(item).toEqual({ | ||
email: '[email protected]', | ||
test_type: 'bigint', | ||
test_bigint: BigInt('90071992547409911234'), | ||
test_bigint_coerce: BigInt('12345') | ||
}) | ||
expect(item).toMatchInlineSnapshot(` | ||
{ | ||
"email": "[email protected]", | ||
"test_bigint": 99999999999999999999999999999999999999n, | ||
"test_bigint_coerce": 12345n, | ||
"test_type": "bigint", | ||
} | ||
`) | ||
}) | ||
|
||
it('parses bigint sets', () => { | ||
const item = TestEntity.parse({ | ||
pk: '[email protected]', | ||
sk: 'bigint', | ||
test_bigint_set_type: new Set([ | ||
toDynamoBigInt(BigInt('90071992547409911234')), | ||
toDynamoBigInt(BigInt('-90071992547409911234')), | ||
{ value: '90071992547409911234' }, | ||
{ value: '-90071992547409911234' }, | ||
1234 | ||
]), | ||
}) | ||
expect(item).toEqual({ | ||
email: '[email protected]', | ||
test_type: 'bigint', | ||
test_bigint_set_type: [ | ||
BigInt('90071992547409911234'), | ||
BigInt('-90071992547409911234'), | ||
BigInt(1234), | ||
] | ||
]) | ||
}) | ||
expect(item).toMatchInlineSnapshot(` | ||
{ | ||
"email": "[email protected]", | ||
"test_bigint_set_type": [ | ||
90071992547409911234n, | ||
-90071992547409911234n, | ||
1234n, | ||
], | ||
"test_type": "bigint", | ||
} | ||
`) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters