Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update the tests to use the Promise-based API #1349

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
3340ca4
test: add test constructors for promise-based clients
owenpearson Apr 26, 2023
1ca52a3
test: add restTestOnJsonMsgpackAsync
owenpearson May 4, 2023
76a1e63
test: convert rest auth tests to Promise API
owenpearson Apr 26, 2023
af38ec8
test: convert rest capability tests to Promise API
owenpearson Apr 26, 2023
a1fb8dd
test: convert rest fallbacks tests to Promise API
owenpearson Apr 26, 2023
6d0d329
test: convert rest history tests to Promise API
owenpearson Apr 26, 2023
b07d032
test: remove legacy rest history promise test
owenpearson Apr 26, 2023
24d299e
test: convert rest http tests to Promise API
owenpearson Apr 26, 2023
d40ea8f
test: convert rest constructor tests to Promise API
owenpearson Apr 26, 2023
152f4e5
test: convert rest message tests to Promise API
owenpearson Apr 26, 2023
8b9e0f9
test: remove legacy rest message promise test
owenpearson Apr 26, 2023
d76a03f
test: convert rest presence tests to Promise API
owenpearson Apr 27, 2023
4ef4a98
test: remove legacy rest presence promise test
owenpearson Apr 27, 2023
844af87
test: convert rest push tests to Promise API
owenpearson Apr 27, 2023
469229b
test: remove legacy rest push promise tests
owenpearson Apr 27, 2023
1e698e2
test: convert rest request tests to Promise API
owenpearson Apr 27, 2023
b694963
test: remove legacy rest request promise test
owenpearson Apr 27, 2023
f882997
test: convert rest stats tests to Promise API
owenpearson Apr 27, 2023
2448be7
test: remove legacy rest stats promise test
owenpearson Apr 27, 2023
44808ed
test: convert rest status test to Promise API
owenpearson Apr 27, 2023
e9081a3
test: remove legacy rest status promise test
owenpearson Apr 27, 2023
edcecfa
test: convert rest time test to Promise API
owenpearson Apr 27, 2023
6796bed
test: remove legacy rest time promise test
owenpearson Apr 27, 2023
17d2aaa
Remove test of Ably.Rest.Callbacks
lawrence-forooghian Jun 20, 2023
a36fe51
Remove "Async" from name of restTestOnJsonMsgpackAsync
lawrence-forooghian Jun 20, 2023
a1c3592
Remove parts of test relating to setOptions calling its callback imme…
lawrence-forooghian Jun 20, 2023
050b95b
Prepare realtime channel publish disallowed test for conversion to Pr…
lawrence-forooghian Jun 20, 2023
43a2d1d
Update Realtime tests to use SDK’s Promise-based API
lawrence-forooghian Jun 14, 2023
45b9c3b
Remove obsolete Promise-based Realtime tests
lawrence-forooghian Jun 22, 2023
d0f034e
Remove "Promise" from name of Ably*Promise helpers
lawrence-forooghian Jun 19, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions test/browser/http.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
define(['ably', 'shared_helper', 'chai'], function (Ably, helper, chai) {
var rest;
var expect = chai.expect;
var whenPromiseSettles = helper.whenPromiseSettles;

describe('rest/http/fetch', function () {
this.timeout(60 * 1000);
Expand Down Expand Up @@ -33,15 +34,15 @@ define(['ably', 'shared_helper', 'chai'], function (Ably, helper, chai) {

it('Should succeed in using fetch to publish a message', function (done) {
const channel = rest.channels.get('http_test_channel');
channel.publish('test', 'Testing fetch support', (err) => {
whenPromiseSettles(channel.publish('test', 'Testing fetch support'), (err) => {
expect(err).to.not.exist;
done();
});
});

it('Should pass errors correctly', function (done) {
const channel = rest.channels.get('');
channel.publish('test', 'Invalid message', (err) => {
whenPromiseSettles(channel.publish('test', 'Invalid message'), (err) => {
expect(err).to.exist;
done();
});
Expand Down
5 changes: 3 additions & 2 deletions test/browser/simple.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

define(['ably', 'shared_helper', 'chai'], function (Ably, helper, chai) {
var expect = chai.expect;
var whenPromiseSettles = helper.whenPromiseSettles;

describe('browser/simple', function () {
this.timeout(60 * 1000);
Expand Down Expand Up @@ -71,7 +72,7 @@ define(['ably', 'shared_helper', 'chai'], function (Ably, helper, chai) {
ably.connection.on('connected', function () {
connectionTimeout.stop();
heartbeatTimeout = failWithin(25, done, ably, 'wait for heartbeat');
ably.connection.ping(function (err) {
whenPromiseSettles(ably.connection.ping(), function (err) {
heartbeatTimeout.stop();
done(err);
ably.close();
Expand Down Expand Up @@ -115,7 +116,7 @@ define(['ably', 'shared_helper', 'chai'], function (Ably, helper, chai) {
receiveMessagesTimeout = failWithin(15, done, ably, 'wait for published messages to be received');

timer = setInterval(function () {
channel.publish('event0', 'Hello world at: ' + new Date(), function (err) {
whenPromiseSettles(channel.publish('event0', 'Hello world at: ' + new Date()), function (err) {
sentCbCount++;
checkFinish();
});
Expand Down
4 changes: 2 additions & 2 deletions test/common/modules/client_module.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@ define(['ably', 'globals', 'test/common/modules/testapp_module'], function (Ably
}

function ablyRest(options) {
return new Ably.Rest(ablyClientOptions(options));
return new Ably.Rest.Promise(ablyClientOptions(options));
}

function ablyRealtime(options) {
return new Ably.Realtime(ablyClientOptions(options));
return new Ably.Realtime.Promise(ablyClientOptions(options));
}

return (module.exports = {
Expand Down
22 changes: 18 additions & 4 deletions test/common/modules/shared_helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,19 @@ define([
});
}

/**
* Uses a callback to communicate the result of a `Promise`. The first argument passed to the callback will be either an error (when the promise is rejected) or `null` (when the promise is fulfilled). In the case where the promise is fulfilled, the resulting value will be passed to the callback as a second argument.
*/
function whenPromiseSettles(promise, callback) {
promise
.then((result) => {
callback(null, result);
})
.catch((err) => {
callback(err);
});
}

function simulateDroppedConnection(realtime) {
// Go into the 'disconnected' state before actually disconnecting the transports
// to avoid the instantaneous reconnect attempt that would be triggered in
Expand Down Expand Up @@ -150,11 +163,11 @@ define([

function restTestOnJsonMsgpack(name, testFn, skip) {
var itFn = skip ? it.skip : it;
itFn(name + ' with binary protocol', function (done) {
testFn(done, new clientModule.AblyRest({ useBinaryProtocol: true }), name + '_binary');
itFn(name + ' with binary protocol', async function () {
await testFn(new clientModule.AblyRest({ useBinaryProtocol: true }), name + '_binary');
});
itFn(name + ' with text protocol', function (done) {
testFn(done, new clientModule.AblyRest({ useBinaryProtocol: false }), name + '_text');
itFn(name + ' with text protocol', async function () {
await testFn(new clientModule.AblyRest({ useBinaryProtocol: false }), name + '_text');
});
}

Expand Down Expand Up @@ -235,5 +248,6 @@ define([
unroutableAddress: unroutableAddress,
arrFind: arrFind,
arrFilter: arrFilter,
whenPromiseSettles: whenPromiseSettles,
});
});
2 changes: 0 additions & 2 deletions test/realtime/api.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ define(['ably', 'chai'], function (Ably, chai) {
it('Client constructors', function () {
expect(typeof Ably.Realtime).to.equal('function');
expect(typeof Ably.Realtime.Promise).to.equal('function');
expect(typeof Ably.Realtime.Callbacks).to.equal('function');
expect(Ably.Realtime.Callbacks).to.equal(Ably.Realtime);
});

it('Crypto', function () {
Expand Down
Loading