-
-
Notifications
You must be signed in to change notification settings - Fork 4.8k
feat: Add support for Decimal128 data type #10083
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
YazanAlkhalil
wants to merge
6
commits into
parse-community:alpha
Choose a base branch
from
YazanAlkhalil:feat/decimal128-support
base: alpha
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
878c74c
feat: Add support for Decimal128 data type
6656598
test: Add Decimal128 GraphQL scalar unit tests
4ec8a5e
fix: Address CodeRabbit review feedback for Decimal128
8e55144
test: Add unit tests for Decimal128 GraphQL transformers
66cb506
fix: Handle nested Decimal128 values and improve test coverage
588d4e0
fix: Use Kind.STRING check in DECIMAL128 parseLiteral object form
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,373 @@ | ||
| 'use strict'; | ||
|
|
||
| const request = require('../lib/request'); | ||
|
|
||
| describe('Parse Decimal128', () => { | ||
| it('should save and retrieve a Decimal128 value via REST API', async () => { | ||
| const createResponse = await request({ | ||
| method: 'POST', | ||
| url: 'http://localhost:8378/1/classes/TestDecimal', | ||
| headers: { | ||
| 'X-Parse-Application-Id': 'test', | ||
| 'X-Parse-Master-Key': 'test', | ||
| 'Content-Type': 'application/json', | ||
| }, | ||
| body: { | ||
| amount: { | ||
| __type: 'Decimal128', | ||
| value: '12345678901234567890.123456789', | ||
| }, | ||
| }, | ||
| }); | ||
| expect(createResponse.data.objectId).toBeDefined(); | ||
|
|
||
| const getResponse = await request({ | ||
| url: `http://localhost:8378/1/classes/TestDecimal/${createResponse.data.objectId}`, | ||
| headers: { | ||
| 'X-Parse-Application-Id': 'test', | ||
| 'X-Parse-Master-Key': 'test', | ||
| }, | ||
| }); | ||
| expect(getResponse.data.amount).toEqual({ | ||
| __type: 'Decimal128', | ||
| value: '12345678901234567890.123456789', | ||
| }); | ||
| }); | ||
|
|
||
| it('should update a Decimal128 value', async () => { | ||
| const createResponse = await request({ | ||
| method: 'POST', | ||
| url: 'http://localhost:8378/1/classes/TestDecimal', | ||
| headers: { | ||
| 'X-Parse-Application-Id': 'test', | ||
| 'X-Parse-Master-Key': 'test', | ||
| 'Content-Type': 'application/json', | ||
| }, | ||
| body: { | ||
| amount: { | ||
| __type: 'Decimal128', | ||
| value: '100.50', | ||
| }, | ||
| }, | ||
| }); | ||
|
|
||
| await request({ | ||
| method: 'PUT', | ||
| url: `http://localhost:8378/1/classes/TestDecimal/${createResponse.data.objectId}`, | ||
| headers: { | ||
| 'X-Parse-Application-Id': 'test', | ||
| 'X-Parse-Master-Key': 'test', | ||
| 'Content-Type': 'application/json', | ||
| }, | ||
| body: { | ||
| amount: { | ||
| __type: 'Decimal128', | ||
| value: '200.75', | ||
| }, | ||
| }, | ||
| }); | ||
|
|
||
| const getResponse = await request({ | ||
| url: `http://localhost:8378/1/classes/TestDecimal/${createResponse.data.objectId}`, | ||
| headers: { | ||
| 'X-Parse-Application-Id': 'test', | ||
| 'X-Parse-Master-Key': 'test', | ||
| }, | ||
| }); | ||
| expect(getResponse.data.amount).toEqual({ | ||
| __type: 'Decimal128', | ||
| value: '200.75', | ||
| }); | ||
| }); | ||
|
|
||
| it('should query with $gt comparison on Decimal128', async () => { | ||
| const values = ['10.5', '20.5', '30.5']; | ||
| for (const val of values) { | ||
| await request({ | ||
| method: 'POST', | ||
| url: 'http://localhost:8378/1/classes/DecimalQuery', | ||
| headers: { | ||
| 'X-Parse-Application-Id': 'test', | ||
| 'X-Parse-Master-Key': 'test', | ||
| 'Content-Type': 'application/json', | ||
| }, | ||
| body: { | ||
| amount: { __type: 'Decimal128', value: val }, | ||
| }, | ||
| }); | ||
| } | ||
|
|
||
| const queryResponse = await request({ | ||
| url: 'http://localhost:8378/1/classes/DecimalQuery', | ||
| qs: { | ||
| where: JSON.stringify({ | ||
| amount: { $gt: { __type: 'Decimal128', value: '15.0' } }, | ||
| }), | ||
| }, | ||
| headers: { | ||
| 'X-Parse-Application-Id': 'test', | ||
| 'X-Parse-Master-Key': 'test', | ||
| }, | ||
| }); | ||
| expect(queryResponse.data.results.length).toBe(2); | ||
| const resultValues = queryResponse.data.results.map(r => r.amount.value).sort(); | ||
| expect(resultValues).toEqual(['20.5', '30.5']); | ||
| }); | ||
|
|
||
| it('should query with $lt comparison on Decimal128', async () => { | ||
| const values = ['100', '200', '300']; | ||
| for (const val of values) { | ||
| await request({ | ||
| method: 'POST', | ||
| url: 'http://localhost:8378/1/classes/DecimalLt', | ||
| headers: { | ||
| 'X-Parse-Application-Id': 'test', | ||
| 'X-Parse-Master-Key': 'test', | ||
| 'Content-Type': 'application/json', | ||
| }, | ||
| body: { | ||
| amount: { __type: 'Decimal128', value: val }, | ||
| }, | ||
| }); | ||
| } | ||
|
|
||
| const queryResponse = await request({ | ||
| url: 'http://localhost:8378/1/classes/DecimalLt', | ||
| qs: { | ||
| where: JSON.stringify({ | ||
| amount: { $lt: { __type: 'Decimal128', value: '250' } }, | ||
| }), | ||
| }, | ||
| headers: { | ||
| 'X-Parse-Application-Id': 'test', | ||
| 'X-Parse-Master-Key': 'test', | ||
| }, | ||
| }); | ||
| expect(queryResponse.data.results.length).toBe(2); | ||
| const resultValues = queryResponse.data.results.map(r => r.amount.value).sort(); | ||
| expect(resultValues).toEqual(['100', '200']); | ||
| }); | ||
|
|
||
| it('should handle high-precision Decimal128 values', async () => { | ||
| const highPrecisionValue = '12345678901234567890.12345678901234'; | ||
| const createResponse = await request({ | ||
| method: 'POST', | ||
| url: 'http://localhost:8378/1/classes/DecimalPrecision', | ||
| headers: { | ||
| 'X-Parse-Application-Id': 'test', | ||
| 'X-Parse-Master-Key': 'test', | ||
| 'Content-Type': 'application/json', | ||
| }, | ||
| body: { | ||
| amount: { __type: 'Decimal128', value: highPrecisionValue }, | ||
| }, | ||
| }); | ||
|
|
||
| const getResponse = await request({ | ||
| url: `http://localhost:8378/1/classes/DecimalPrecision/${createResponse.data.objectId}`, | ||
| headers: { | ||
| 'X-Parse-Application-Id': 'test', | ||
| 'X-Parse-Master-Key': 'test', | ||
| }, | ||
| }); | ||
| expect(getResponse.data.amount).toEqual({ | ||
| __type: 'Decimal128', | ||
| value: highPrecisionValue, | ||
| }); | ||
| }); | ||
|
|
||
| it('should handle negative Decimal128 values', async () => { | ||
| const createResponse = await request({ | ||
| method: 'POST', | ||
| url: 'http://localhost:8378/1/classes/DecimalNeg', | ||
| headers: { | ||
| 'X-Parse-Application-Id': 'test', | ||
| 'X-Parse-Master-Key': 'test', | ||
| 'Content-Type': 'application/json', | ||
| }, | ||
| body: { | ||
| amount: { __type: 'Decimal128', value: '-12345.6789' }, | ||
| }, | ||
| }); | ||
|
|
||
| const getResponse = await request({ | ||
| url: `http://localhost:8378/1/classes/DecimalNeg/${createResponse.data.objectId}`, | ||
| headers: { | ||
| 'X-Parse-Application-Id': 'test', | ||
| 'X-Parse-Master-Key': 'test', | ||
| }, | ||
| }); | ||
| expect(getResponse.data.amount).toEqual({ | ||
| __type: 'Decimal128', | ||
| value: '-12345.6789', | ||
| }); | ||
| }); | ||
|
|
||
| it('should handle zero Decimal128 value', async () => { | ||
| const createResponse = await request({ | ||
| method: 'POST', | ||
| url: 'http://localhost:8378/1/classes/DecimalZero', | ||
| headers: { | ||
| 'X-Parse-Application-Id': 'test', | ||
| 'X-Parse-Master-Key': 'test', | ||
| 'Content-Type': 'application/json', | ||
| }, | ||
| body: { | ||
| amount: { __type: 'Decimal128', value: '0' }, | ||
| }, | ||
| }); | ||
|
|
||
| const getResponse = await request({ | ||
| url: `http://localhost:8378/1/classes/DecimalZero/${createResponse.data.objectId}`, | ||
| headers: { | ||
| 'X-Parse-Application-Id': 'test', | ||
| 'X-Parse-Master-Key': 'test', | ||
| }, | ||
| }); | ||
| expect(getResponse.data.amount).toEqual({ | ||
| __type: 'Decimal128', | ||
| value: '0', | ||
| }); | ||
| }); | ||
|
|
||
| it('should set Decimal128 field via schema API', async () => { | ||
| await request({ | ||
| method: 'POST', | ||
| url: 'http://localhost:8378/1/schemas/DecimalSchema', | ||
| headers: { | ||
| 'X-Parse-Application-Id': 'test', | ||
| 'X-Parse-Master-Key': 'test', | ||
| 'Content-Type': 'application/json', | ||
| }, | ||
| body: { | ||
| className: 'DecimalSchema', | ||
| fields: { | ||
| amount: { type: 'Decimal128' }, | ||
| }, | ||
| }, | ||
| }); | ||
|
|
||
| const schemaResponse = await request({ | ||
| url: 'http://localhost:8378/1/schemas/DecimalSchema', | ||
| headers: { | ||
| 'X-Parse-Application-Id': 'test', | ||
| 'X-Parse-Master-Key': 'test', | ||
| }, | ||
| }); | ||
| expect(schemaResponse.data.fields.amount.type).toBe('Decimal128'); | ||
| }); | ||
|
|
||
| it('should delete Decimal128 field value', async () => { | ||
| const createResponse = await request({ | ||
| method: 'POST', | ||
| url: 'http://localhost:8378/1/classes/DecimalDel', | ||
| headers: { | ||
| 'X-Parse-Application-Id': 'test', | ||
| 'X-Parse-Master-Key': 'test', | ||
| 'Content-Type': 'application/json', | ||
| }, | ||
| body: { | ||
| amount: { __type: 'Decimal128', value: '42.0' }, | ||
| }, | ||
| }); | ||
|
|
||
| await request({ | ||
| method: 'PUT', | ||
| url: `http://localhost:8378/1/classes/DecimalDel/${createResponse.data.objectId}`, | ||
| headers: { | ||
| 'X-Parse-Application-Id': 'test', | ||
| 'X-Parse-Master-Key': 'test', | ||
| 'Content-Type': 'application/json', | ||
| }, | ||
| body: { | ||
| amount: { __op: 'Delete' }, | ||
| }, | ||
| }); | ||
|
|
||
| const getResponse = await request({ | ||
| url: `http://localhost:8378/1/classes/DecimalDel/${createResponse.data.objectId}`, | ||
| headers: { | ||
| 'X-Parse-Application-Id': 'test', | ||
| 'X-Parse-Master-Key': 'test', | ||
| }, | ||
| }); | ||
| expect(getResponse.data.amount).toBeUndefined(); | ||
| }); | ||
|
|
||
| it('should query with equality on Decimal128', async () => { | ||
| await request({ | ||
| method: 'POST', | ||
| url: 'http://localhost:8378/1/classes/DecimalEq', | ||
| headers: { | ||
| 'X-Parse-Application-Id': 'test', | ||
| 'X-Parse-Master-Key': 'test', | ||
| 'Content-Type': 'application/json', | ||
| }, | ||
| body: { | ||
| amount: { __type: 'Decimal128', value: '99.99' }, | ||
| label: 'target', | ||
| }, | ||
| }); | ||
| await request({ | ||
| method: 'POST', | ||
| url: 'http://localhost:8378/1/classes/DecimalEq', | ||
| headers: { | ||
| 'X-Parse-Application-Id': 'test', | ||
| 'X-Parse-Master-Key': 'test', | ||
| 'Content-Type': 'application/json', | ||
| }, | ||
| body: { | ||
| amount: { __type: 'Decimal128', value: '50.00' }, | ||
| label: 'other', | ||
| }, | ||
| }); | ||
|
|
||
| const queryResponse = await request({ | ||
| url: 'http://localhost:8378/1/classes/DecimalEq', | ||
| qs: { | ||
| where: JSON.stringify({ | ||
| amount: { __type: 'Decimal128', value: '99.99' }, | ||
| }), | ||
| }, | ||
| headers: { | ||
| 'X-Parse-Application-Id': 'test', | ||
| 'X-Parse-Master-Key': 'test', | ||
| }, | ||
| }); | ||
| expect(queryResponse.data.results.length).toBe(1); | ||
| expect(queryResponse.data.results[0].label).toBe('target'); | ||
| }); | ||
|
|
||
| it('should handle Decimal128 nested inside an Object field', async () => { | ||
| const createResponse = await request({ | ||
| method: 'POST', | ||
| url: 'http://localhost:8378/1/classes/DecimalNested', | ||
| headers: { | ||
| 'X-Parse-Application-Id': 'test', | ||
| 'X-Parse-Master-Key': 'test', | ||
| 'Content-Type': 'application/json', | ||
| }, | ||
| body: { | ||
| metadata: { | ||
| price: { __type: 'Decimal128', value: '19.99' }, | ||
| currency: 'USD', | ||
| }, | ||
| }, | ||
| }); | ||
| expect(createResponse.data.objectId).toBeDefined(); | ||
|
|
||
| const getResponse = await request({ | ||
| url: `http://localhost:8378/1/classes/DecimalNested/${createResponse.data.objectId}`, | ||
| headers: { | ||
| 'X-Parse-Application-Id': 'test', | ||
| 'X-Parse-Master-Key': 'test', | ||
| }, | ||
| }); | ||
| expect(getResponse.data.metadata).toBeDefined(); | ||
| expect(getResponse.data.metadata.currency).toBe('USD'); | ||
| expect(getResponse.data.metadata.price).toEqual({ | ||
| __type: 'Decimal128', | ||
| value: '19.99', | ||
| }); | ||
| }); | ||
| }); | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.