Skip to content

Commit 8da19ec

Browse files
committed
test: bugfix bytestring yson test
1 parent 5e0b839 commit 8da19ec

File tree

3 files changed

+15
-31
lines changed

3 files changed

+15
-31
lines changed

src/__tests__/bytestring-identity.test.ts

Lines changed: 13 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,19 @@
11
import Driver from '../driver';
2-
import {
3-
destroyDriver,
4-
initDriver,
5-
TABLE
6-
} from '../test-utils';
2+
import {destroyDriver, initDriver, TABLE} from '../test-utils';
73
import {Column, Session, TableDescription} from '../table';
8-
import {declareType, TypedData, Types} from "../types";
9-
import {withRetries} from "../retries";
10-
4+
import {declareType, TypedData, Types} from '../types';
5+
import {withRetries} from '../retries';
116

127
async function createTable(session: Session) {
138
await session.dropTable(TABLE);
149
await session.createTable(
1510
TABLE,
1611
new TableDescription()
17-
.withColumn(new Column(
18-
'id',
19-
Types.optional(Types.UINT64),
20-
))
21-
.withColumn(new Column(
22-
'field1',
23-
Types.optional(Types.TEXT),
24-
))
25-
.withColumn(new Column(
26-
'field2',
27-
Types.optional(Types.BYTES),
28-
))
29-
.withColumn(new Column(
30-
'field3',
31-
Types.optional(Types.YSON),
32-
))
33-
.withPrimaryKey('id')
12+
.withColumn(new Column('id', Types.optional(Types.UINT64)))
13+
.withColumn(new Column('field1', Types.optional(Types.TEXT)))
14+
.withColumn(new Column('field2', Types.optional(Types.BYTES)))
15+
.withColumn(new Column('field3', Types.optional(Types.YSON)))
16+
.withPrimaryKey('id'),
3417
);
3518
}
3619

@@ -65,15 +48,15 @@ class Row extends TypedData {
6548

6649
export async function fillTableWithData(session: Session, rows: Row[]) {
6750
const query = `
68-
DECLARE $data AS List<Struct<id: Uint64, field1: String, field2: String, field3: Yson>>;
51+
DECLARE $data AS List<Struct<id: Uint64, field1: Text, field2: String, field3: Yson>>;
6952
7053
REPLACE INTO ${TABLE}
7154
SELECT * FROM AS_TABLE($data);`;
7255

7356
await withRetries(async () => {
7457
const preparedQuery = await session.prepareQuery(query);
7558
await session.executeQuery(preparedQuery, {
76-
'$data': Row.asTypedCollection(rows),
59+
$data: Row.asTypedCollection(rows),
7760
});
7861
});
7962
}
@@ -86,7 +69,7 @@ describe('bytestring identity', () => {
8669
id: 0,
8770
field1: 'zero',
8871
field2: Buffer.from('half'),
89-
field3: Buffer.from('<a=1>[3;%false]')
72+
field3: Buffer.from('<a=1>[3;%false]'),
9073
}),
9174
];
9275

@@ -103,8 +86,8 @@ describe('bytestring identity', () => {
10386
});
10487
});
10588

106-
it('Types.STRING does not keep the original string in write-read cycle', () => {
107-
expect(actualRows[0].field1).not.toEqual('zero');
89+
it('Types.TEXT keeps the original string in write-read cycle', () => {
90+
expect(actualRows[0].field1).toEqual('zero');
10891
});
10992

11093
it('Types.BYTES keeps the original string in write-read cycle', () => {

src/__tests__/types.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -423,7 +423,7 @@ describe('Types', () => {
423423
const data = {
424424
string_value: Buffer.from('foo'),
425425
utf8_value: 'hello',
426-
yson_value: Buffer.from('<a=1>[3;%false]'),
426+
yson_value: '<a=1>[3;%false]',
427427
json_value: '{"a":1,"b":null}',
428428
json_document_value: '[]',
429429
};

src/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -451,6 +451,7 @@ function objectFromValue(type: IType, value: unknown) {
451451
const {typeId} = type;
452452
switch (typeId) {
453453
case PrimitiveTypeId.YSON:
454+
return (value as Buffer).toString('utf8');
454455
case PrimitiveTypeId.STRING:
455456
return value as Buffer;
456457
case PrimitiveTypeId.DATE:

0 commit comments

Comments
 (0)