Skip to content

Commit 5cd4e08

Browse files
committed
Fix liveobjects realtime tests as a result of primitiveKeyData refactor
1 parent 1d496f1 commit 5cd4e08

File tree

1 file changed

+27
-43
lines changed

1 file changed

+27
-43
lines changed

test/realtime/liveobjects.test.js

Lines changed: 27 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -573,18 +573,8 @@ define(['ably', 'shared_helper', 'chai', 'liveobjects', 'liveobjects_helper'], f
573573

574574
const primitiveKeyData = LiveObjectsHelper.primitiveKeyData;
575575
const primitiveMapsFixtures = [
576-
{ name: 'emptyMap' },
577-
{
578-
name: 'valuesMap',
579-
entries: primitiveKeyData.reduce((acc, v) => {
580-
acc[v.key] = { data: v.jsonData };
581-
return acc;
582-
}, {}),
583-
restData: primitiveKeyData.reduce((acc, v) => {
584-
acc[v.key] = v.jsonData;
585-
return acc;
586-
}, {}),
587-
},
576+
{ name: 'emptyMap', entries: [] },
577+
{ name: 'valuesMap', entries: primitiveKeyData },
588578
];
589579
const countersFixtures = [
590580
{ name: 'emptyCounter' },
@@ -1541,7 +1531,9 @@ define(['ably', 'shared_helper', 'chai', 'liveobjects', 'liveobjects_helper'], f
15411531
objectsHelper.createAndSetOnMap(channelName, {
15421532
mapObjectId: 'root',
15431533
key: fixture.name,
1544-
createOp: objectsHelper.mapCreateRestOp({ data: fixture.restData }),
1534+
createOp: objectsHelper.mapCreateRestOp({
1535+
data: Object.fromEntries(fixture.entries.map((v) => [v.key, v.jsonData])),
1536+
}),
15451537
}),
15461538
),
15471539
);
@@ -1558,18 +1550,15 @@ define(['ably', 'shared_helper', 'chai', 'liveobjects', 'liveobjects_helper'], f
15581550
expectInstanceOf(map._value, 'LiveMap', `Check map at "${mapKey}" key in root is of type LiveMap`);
15591551

15601552
// check primitive maps have correct values
1561-
expect(map.size()).to.equal(
1562-
Object.keys(fixture.entries ?? {}).length,
1563-
`Check map "${mapKey}" has correct number of keys`,
1564-
);
1553+
expect(map.size()).to.equal(fixture.entries.length, `Check map "${mapKey}" has correct number of keys`);
15651554

1566-
Object.entries(fixture.entries ?? {}).forEach(([key, keyData]) => {
1555+
fixture.entries.forEach((keyData) => {
15671556
checkKeyDataOnInstance({
15681557
helper,
1569-
key,
1558+
key: keyData.key,
15701559
keyData,
15711560
instance: map,
1572-
msg: `Check map "${mapKey}" has correct value for "${key}" key`,
1561+
msg: `Check map "${mapKey}" has correct value for "${keyData.key}" key`,
15731562
});
15741563
});
15751564
});
@@ -4197,22 +4186,20 @@ define(['ably', 'shared_helper', 'chai', 'liveobjects', 'liveobjects_helper'], f
41974186

41984187
await Promise.all(
41994188
primitiveMapsFixtures.map(async (mapFixture) => {
4200-
const entries = mapFixture.entries
4201-
? Object.entries(mapFixture.entries).reduce((acc, [key, keyData]) => {
4202-
let value;
4203-
if (keyData.jsonData.bytes != null) {
4204-
helper.recordPrivateApi('call.BufferUtils.base64Decode');
4205-
value = BufferUtils.base64Decode(keyData.jsonData.bytes);
4206-
} else if (keyData.jsonData.json != null) {
4207-
value = JSON.parse(keyData.jsonData.json);
4208-
} else {
4209-
value = keyData.jsonData.number ?? keyData.jsonData.string ?? keyData.jsonData.boolean;
4210-
}
4211-
4212-
acc[key] = value;
4213-
return acc;
4214-
}, {})
4215-
: undefined;
4189+
const entries = Object.fromEntries(
4190+
mapFixture.entries.map((keyData) => {
4191+
let value;
4192+
if (keyData.jsonData.bytes != null) {
4193+
helper.recordPrivateApi('call.BufferUtils.base64Decode');
4194+
value = BufferUtils.base64Decode(keyData.jsonData.bytes);
4195+
} else if (keyData.jsonData.json != null) {
4196+
value = JSON.parse(keyData.jsonData.json);
4197+
} else {
4198+
value = keyData.jsonData.number ?? keyData.jsonData.string ?? keyData.jsonData.boolean;
4199+
}
4200+
return [keyData.key, value];
4201+
}),
4202+
);
42164203

42174204
return entryInstance.set(mapFixture.name, LiveMap.create(entries));
42184205
}),
@@ -4226,18 +4213,15 @@ define(['ably', 'shared_helper', 'chai', 'liveobjects', 'liveobjects_helper'], f
42264213
helper.recordPrivateApi('read.DefaultInstance._value');
42274214
expectInstanceOf(map._value, 'LiveMap', `Check map instance #${i + 1} is of an expected class`);
42284215

4229-
expect(map.size()).to.equal(
4230-
Object.keys(fixture.entries ?? {}).length,
4231-
`Check map #${i + 1} has correct number of keys`,
4232-
);
4216+
expect(map.size()).to.equal(fixture.entries.length, `Check map #${i + 1} has correct number of keys`);
42334217

4234-
Object.entries(fixture.entries ?? {}).forEach(([key, keyData]) => {
4218+
fixture.entries.forEach((keyData) => {
42354219
checkKeyDataOnInstance({
42364220
helper,
4237-
key,
4221+
key: keyData.key,
42384222
keyData,
42394223
instance: map,
4240-
msg: `Check map #${i + 1} has correct value for "${key}" key`,
4224+
msg: `Check map #${i + 1} has correct value for "${keyData.key}" key`,
42414225
});
42424226
});
42434227
}

0 commit comments

Comments
 (0)