Skip to content

Commit 7fecab1

Browse files
committed
DX-1204: add v1 callback runtime tests
1 parent f6b39ef commit 7fecab1

4 files changed

Lines changed: 191 additions & 0 deletions

File tree

test/realtime/auth.test.js

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1643,5 +1643,41 @@ define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, Helper, async
16431643
});
16441644
};
16451645
});
1646+
1647+
/**
1648+
* v1-style trailing-callback shape on Auth.{authorize, requestToken,
1649+
* createTokenRequest} throws synchronously with a steering ErrorInfo.
1650+
*/
1651+
[
1652+
{ method: 'authorize', invoke: (auth) => auth.authorize(null, null, () => {}) },
1653+
{ method: 'requestToken', invoke: (auth) => auth.requestToken(null, null, () => {}) },
1654+
{ method: 'createTokenRequest', invoke: (auth) => auth.createTokenRequest(null, null, () => {}) },
1655+
].forEach(function (testCase) {
1656+
it('v1_callback_auth_' + testCase.method + '_throws_synchronously', function (done) {
1657+
var helper = this.test.helper,
1658+
realtime = helper.AblyRealtime();
1659+
1660+
try {
1661+
testCase.invoke(realtime.auth);
1662+
helper.closeAndFinish(
1663+
done,
1664+
realtime,
1665+
new Error('expected auth.' + testCase.method + '() to throw on v1 callback shape'),
1666+
);
1667+
} catch (err) {
1668+
try {
1669+
expect(err.code).to.equal(40000);
1670+
expect(err.message).to.contain('v1 callback signature');
1671+
expect(err.message).to.contain('no longer supported');
1672+
expect(err.hint).to.be.a('string');
1673+
expect(err.hint).to.contain('Remove the trailing callback');
1674+
expect(err.hint).to.contain('https://github.com/ably/ably-js/blob/main/docs/migration-guides/v2/lib.md');
1675+
helper.closeAndFinish(done, realtime);
1676+
} catch (assertionErr) {
1677+
helper.closeAndFinish(done, realtime, assertionErr);
1678+
}
1679+
}
1680+
});
1681+
});
16461682
});
16471683
});

test/realtime/channel.test.js

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1449,6 +1449,78 @@ define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, Helper, async
14491449
});
14501450
});
14511451

1452+
/**
1453+
* v1-style trailing-callback shape on RealtimeChannel.{publish, subscribe,
1454+
* unsubscribe, history} throws synchronously with a steering ErrorInfo whose
1455+
* message diagnoses *what* went wrong and whose hint prescribes the v2
1456+
* replacement call.
1457+
*/
1458+
[
1459+
{ method: 'publish', invoke: (ch) => ch.publish('event', { hello: 'world' }, () => {}) },
1460+
{
1461+
method: 'subscribe',
1462+
invoke: (ch) =>
1463+
ch.subscribe(
1464+
'event',
1465+
() => {},
1466+
() => {},
1467+
),
1468+
},
1469+
{
1470+
method: 'subscribe_listener_callback',
1471+
invoke: (ch) =>
1472+
ch.subscribe(
1473+
() => {},
1474+
() => {},
1475+
),
1476+
},
1477+
{
1478+
method: 'unsubscribe',
1479+
invoke: (ch) =>
1480+
ch.unsubscribe(
1481+
'event',
1482+
() => {},
1483+
() => {},
1484+
),
1485+
},
1486+
{
1487+
method: 'unsubscribe_listener_callback',
1488+
invoke: (ch) =>
1489+
ch.unsubscribe(
1490+
() => {},
1491+
() => {},
1492+
),
1493+
},
1494+
{ method: 'history', invoke: (ch) => ch.history(null, () => {}) },
1495+
].forEach(function (testCase) {
1496+
it('v1_callback_' + testCase.method + '_throws_synchronously', function (done) {
1497+
var helper = this.test.helper,
1498+
realtime = helper.AblyRealtime(),
1499+
channel = realtime.channels.get('v1cb_channel_' + testCase.method);
1500+
1501+
try {
1502+
testCase.invoke(channel);
1503+
helper.closeAndFinish(
1504+
done,
1505+
realtime,
1506+
new Error('expected ' + testCase.method + '() to throw on v1 callback shape'),
1507+
);
1508+
} catch (err) {
1509+
try {
1510+
expect(err.code).to.equal(40000);
1511+
expect(err.message).to.contain('v1 callback signature');
1512+
expect(err.message).to.contain('no longer supported');
1513+
expect(err.hint).to.be.a('string');
1514+
expect(err.hint).to.contain('Remove the trailing callback');
1515+
expect(err.hint).to.contain('https://github.com/ably/ably-js/blob/main/docs/migration-guides/v2/lib.md');
1516+
helper.closeAndFinish(done, realtime);
1517+
} catch (assertionErr) {
1518+
helper.closeAndFinish(done, realtime, assertionErr);
1519+
}
1520+
}
1521+
});
1522+
});
1523+
14521524
/**
14531525
* A channel attach that times out should be retried
14541526
*

test/realtime/connection.test.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -473,5 +473,32 @@ define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, Helper, async
473473

474474
await helper.closeAndFinishAsync(realtime);
475475
});
476+
477+
/**
478+
* v1-style trailing-callback shape on Connection.ping throws synchronously
479+
* with a steering ErrorInfo.
480+
*/
481+
it('v1_callback_ping_throws_synchronously', function (done) {
482+
const helper = this.test.helper;
483+
const realtime = helper.AblyRealtime();
484+
try {
485+
realtime.connection.ping(function noopCallback(err) {
486+
void err;
487+
});
488+
helper.closeAndFinish(done, realtime, new Error('expected ping() to throw on v1 callback shape'));
489+
} catch (err) {
490+
try {
491+
expect(err.code).to.equal(40000);
492+
expect(err.message).to.contain('v1 callback signature');
493+
expect(err.message).to.contain('no longer supported');
494+
expect(err.hint).to.be.a('string');
495+
expect(err.hint).to.contain('Remove the trailing callback');
496+
expect(err.hint).to.contain('https://github.com/ably/ably-js/blob/main/docs/migration-guides/v2/lib.md');
497+
helper.closeAndFinish(done, realtime);
498+
} catch (assertionErr) {
499+
helper.closeAndFinish(done, realtime, assertionErr);
500+
}
501+
}
502+
});
476503
});
477504
});

test/realtime/presence.test.js

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2309,5 +2309,61 @@ define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, Helper, async
23092309
);
23102310
});
23112311
});
2312+
2313+
/**
2314+
* v1-style trailing-callback shape on RealtimePresence.{enter, update, leave,
2315+
* get, history, subscribe} throws synchronously with a steering ErrorInfo.
2316+
*/
2317+
[
2318+
{ method: 'enter', invoke: (presence) => presence.enter({ data: 'x' }, () => {}) },
2319+
{ method: 'update', invoke: (presence) => presence.update({ data: 'x' }, () => {}) },
2320+
{ method: 'leave', invoke: (presence) => presence.leave({ data: 'x' }, () => {}) },
2321+
{ method: 'get', invoke: (presence) => presence.get(null, () => {}) },
2322+
{ method: 'history', invoke: (presence) => presence.history(null, () => {}) },
2323+
{
2324+
method: 'subscribe',
2325+
invoke: (presence) =>
2326+
presence.subscribe(
2327+
'enter',
2328+
() => {},
2329+
() => {},
2330+
),
2331+
},
2332+
{
2333+
method: 'subscribe_listener_callback',
2334+
invoke: (presence) =>
2335+
presence.subscribe(
2336+
() => {},
2337+
() => {},
2338+
),
2339+
},
2340+
].forEach(function (testCase) {
2341+
it('v1_callback_presence_' + testCase.method + '_throws_synchronously', function (done) {
2342+
var helper = this.test.helper,
2343+
realtime = helper.AblyRealtime({ clientId: testClientId }),
2344+
channel = realtime.channels.get('v1cb_presence_' + testCase.method);
2345+
2346+
try {
2347+
testCase.invoke(channel.presence);
2348+
helper.closeAndFinish(
2349+
done,
2350+
realtime,
2351+
new Error('expected presence.' + testCase.method + '() to throw on v1 callback shape'),
2352+
);
2353+
} catch (err) {
2354+
try {
2355+
expect(err.code).to.equal(40000);
2356+
expect(err.message).to.contain('v1 callback signature');
2357+
expect(err.message).to.contain('no longer supported');
2358+
expect(err.hint).to.be.a('string');
2359+
expect(err.hint).to.contain('Remove the trailing callback');
2360+
expect(err.hint).to.contain('https://github.com/ably/ably-js/blob/main/docs/migration-guides/v2/lib.md');
2361+
helper.closeAndFinish(done, realtime);
2362+
} catch (assertionErr) {
2363+
helper.closeAndFinish(done, realtime, assertionErr);
2364+
}
2365+
}
2366+
});
2367+
});
23122368
});
23132369
});

0 commit comments

Comments
 (0)