Skip to content

Commit c52b7e6

Browse files
committed
DX-1204: add v1 callback runtime tests
1 parent 599df58 commit c52b7e6

4 files changed

Lines changed: 167 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: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1449,6 +1449,62 @@ 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: 'unsubscribe',
1471+
invoke: (ch) =>
1472+
ch.unsubscribe(
1473+
'event',
1474+
() => {},
1475+
() => {},
1476+
),
1477+
},
1478+
{ method: 'history', invoke: (ch) => ch.history(null, () => {}) },
1479+
].forEach(function (testCase) {
1480+
it('v1_callback_' + testCase.method + '_throws_synchronously', function (done) {
1481+
var helper = this.test.helper,
1482+
realtime = helper.AblyRealtime(),
1483+
channel = realtime.channels.get('v1cb_channel_' + testCase.method);
1484+
1485+
try {
1486+
testCase.invoke(channel);
1487+
helper.closeAndFinish(
1488+
done,
1489+
realtime,
1490+
new Error('expected ' + testCase.method + '() to throw on v1 callback shape'),
1491+
);
1492+
} catch (err) {
1493+
try {
1494+
expect(err.code).to.equal(40000);
1495+
expect(err.message).to.contain('v1 callback signature');
1496+
expect(err.message).to.contain('no longer supported');
1497+
expect(err.hint).to.be.a('string');
1498+
expect(err.hint).to.contain('Remove the trailing callback');
1499+
expect(err.hint).to.contain('https://github.com/ably/ably-js/blob/main/docs/migration-guides/v2/lib.md');
1500+
helper.closeAndFinish(done, realtime);
1501+
} catch (assertionErr) {
1502+
helper.closeAndFinish(done, realtime, assertionErr);
1503+
}
1504+
}
1505+
});
1506+
});
1507+
14521508
/**
14531509
* A channel attach that times out should be retried
14541510
*

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: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2309,5 +2309,53 @@ 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+
].forEach(function (testCase) {
2333+
it('v1_callback_presence_' + testCase.method + '_throws_synchronously', function (done) {
2334+
var helper = this.test.helper,
2335+
realtime = helper.AblyRealtime({ clientId: testClientId }),
2336+
channel = realtime.channels.get('v1cb_presence_' + testCase.method);
2337+
2338+
try {
2339+
testCase.invoke(channel.presence);
2340+
helper.closeAndFinish(
2341+
done,
2342+
realtime,
2343+
new Error('expected presence.' + testCase.method + '() to throw on v1 callback shape'),
2344+
);
2345+
} catch (err) {
2346+
try {
2347+
expect(err.code).to.equal(40000);
2348+
expect(err.message).to.contain('v1 callback signature');
2349+
expect(err.message).to.contain('no longer supported');
2350+
expect(err.hint).to.be.a('string');
2351+
expect(err.hint).to.contain('Remove the trailing callback');
2352+
expect(err.hint).to.contain('https://github.com/ably/ably-js/blob/main/docs/migration-guides/v2/lib.md');
2353+
helper.closeAndFinish(done, realtime);
2354+
} catch (assertionErr) {
2355+
helper.closeAndFinish(done, realtime, assertionErr);
2356+
}
2357+
}
2358+
});
2359+
});
23122360
});
23132361
});

0 commit comments

Comments
 (0)