-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* insert/update as spanner.Float when needed * refactor patchFloat
- Loading branch information
Showing
5 changed files
with
100 additions
and
16 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
const { patchFloat, extractFloatFields } = require('./spanner_utils') | ||
const { Spanner } = require ('@google-cloud/spanner') | ||
const { Chance } = require('chance') | ||
const { Uninitialized } = require('test-commons') | ||
|
||
const chance = Chance() | ||
|
||
describe('Spanner utils', () => { | ||
test('patchFloat will wrap with Spanner.float float columns data', () => { | ||
const item = { | ||
floatColumn: ctx.integer, | ||
doubleColumn: ctx.integer, | ||
intColumn: ctx.integer, | ||
field: ctx.text, | ||
} | ||
|
||
const fields = { | ||
floatColumn: { | ||
displayName: 'floatColumn', | ||
type: 'number', | ||
subtype: 'float', | ||
}, | ||
doubleColumn: { | ||
displayName: 'doubleColumn', | ||
type: 'number', | ||
subtype: 'double', | ||
}, | ||
intColumn: { | ||
displayName: 'intColumn', | ||
type: 'number', | ||
subtype: 'int', | ||
}, | ||
field: { | ||
displayName: 'field', | ||
type: 'text', | ||
subtype: 'string' | ||
}, | ||
} | ||
|
||
expect(patchFloat(item, extractFloatFields(fields))).toEqual( | ||
{ | ||
floatColumn: Spanner.float(ctx.integer), | ||
doubleColumn: Spanner.float(ctx.integer), | ||
intColumn: ctx.integer, | ||
field: ctx.text, | ||
} | ||
) | ||
}) | ||
|
||
const ctx = { | ||
integer: Uninitialized, | ||
text: Uninitialized | ||
} | ||
|
||
beforeEach(() => { | ||
ctx.integer = chance.integer() | ||
ctx.text = chance.word() | ||
}) | ||
}) |
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