Skip to content
This repository has been archived by the owner on Jan 15, 2021. It is now read-only.

Commit

Permalink
Update tests with sandbox
Browse files Browse the repository at this point in the history
  • Loading branch information
opetkevich committed Mar 23, 2017
1 parent a06a2a7 commit ea2ff16
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 35 deletions.
21 changes: 10 additions & 11 deletions test/www/jxcore/bv_tests/testPouchDBCheckpointPlugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

var tape = require('../lib/thaliTape');
var testUtils = require('../lib/testUtils');
var sinon = require('sinon');
var randomString = require('randomstring');

var PouchDB = testUtils.getLevelDownPouchDb()
Expand Down Expand Up @@ -59,9 +58,9 @@ function () {
// incomplete solution
return true;
},
function (t) {
var spy = sinon.spy();
var anotherSpy = sinon.spy();
tape.sinonTest(function (t) {
var spy = this.spy();
var anotherSpy = this.spy();

var endTestIfBothSpiesWereCalledOnce = function (test) {
if (spy.callCount > 1 || anotherSpy.callCount > 1) {
Expand All @@ -84,7 +83,7 @@ function (t) {
});

db.put(new Doc()).catch(t.end);
});
}));

test('Call of onCheckpointReached handler on multiple db changes ' +
'that are in the checkpoints plugin delay interval',
Expand All @@ -93,9 +92,9 @@ function () {
// incomplete solution
return true;
},
function (t) {
tape.sinonTest(function (t) {
var ENSURE_DELAY = 1000;
var spy = sinon.spy();
var spy = this.spy();

db.onCheckpointReached(function () {
spy();
Expand All @@ -117,7 +116,7 @@ function (t) {
.catch(function (error) {
t.end(error);
});
});
}));

test('Call of onCheckpointReached handler on multiple db changes ' +
'that are out of the checkpoints plugin delay interval',
Expand All @@ -126,8 +125,8 @@ function () {
// incomplete solution
return true;
},
function (t) {
var spy = sinon.spy();
tape.sinonTest(function (t) {
var spy = this.spy();

var handler = function () {
spy();
Expand All @@ -148,4 +147,4 @@ function (t) {
.catch(function (error) {
t.end(error);
});
});
}));
42 changes: 18 additions & 24 deletions test/www/jxcore/bv_tests/testSSDPServer.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
var tape = require('../lib/thaliTape');

var Promise = require('bluebird');
var sinon = require('sinon');
var express = require('express');

var ThaliMobile = require('thali/NextGeneration/thaliMobile');
Expand All @@ -20,16 +19,11 @@ function callArg(arg) {
arg();
}

var sandbox = null;

var test = tape({
setup: function (t) {
sandbox = sinon.sandbox.create();
t.end();
},
teardown: function (t) {
sandbox.restore();
sandbox = null;
t.end();
}
});
Expand All @@ -39,7 +33,7 @@ test(
function () {
return global.NETWORK_TYPE !== networkTypes.WIFI;
},
function (t) {
tape.sinonTest(function (t) {
function toggleWifi(value) {
ThaliMobileNativeWrapper.emitter.emit('networkChangedNonTCP', {
wifi: value? 'on' : 'off',
Expand All @@ -53,13 +47,13 @@ test(

var wifiInfrastructure = new ThaliWifiInfrastructure();
var serverStartSpy =
sandbox.spy(wifiInfrastructure._getSSDPServer(), 'start');
this.spy(wifiInfrastructure._getSSDPServer(), 'start');
var serverStopSpy =
sandbox.spy(wifiInfrastructure._getSSDPServer(), 'stop');
this.spy(wifiInfrastructure._getSSDPServer(), 'stop');
var clientStartSpy =
sandbox.spy(wifiInfrastructure._getSSDPClient(), 'start');
this.spy(wifiInfrastructure._getSSDPClient(), 'start');
var clientStopSpy =
sandbox.spy(wifiInfrastructure._getSSDPClient(), 'stop');
this.spy(wifiInfrastructure._getSSDPClient(), 'stop');

wifiInfrastructure.start(express.Router(), pskIdToSecret)
.then(function () {
Expand Down Expand Up @@ -101,7 +95,7 @@ test(
'should not be in started state');
t.end();
});
}
})
);

function changeBssid (value) {
Expand Down Expand Up @@ -152,15 +146,15 @@ test(
function () {
return global.NETWORK_TYPE !== networkTypes.WIFI;
},
function (t) {
tape.sinonTest(function (t) {
var wifiInfrastructure = new ThaliWifiInfrastructure();
var ssdpServer = wifiInfrastructure._getSSDPServer();
var ssdpClient = wifiInfrastructure._getSSDPClient();
var stubs = {
serverStart: sandbox.stub(ssdpServer, 'start', callArg),
serverStop: sandbox.stub(ssdpServer, 'stop', callArg),
clientStart: sandbox.stub(ssdpClient, 'start', callArg),
clientStop: sandbox.stub(ssdpClient, 'stop', callArg)
serverStart: this.stub(ssdpServer, 'start', callArg),
serverStop: this.stub(ssdpServer, 'stop', callArg),
clientStart: this.stub(ssdpClient, 'start', callArg),
clientStop: this.stub(ssdpClient, 'stop', callArg)
};
var context = { t: t, stubs: stubs };
var testBssid = testBssidChangeReaction.bind(null, context);
Expand Down Expand Up @@ -198,7 +192,7 @@ test(
'should not be in started state');
t.end();
});
}
})
);

test(
Expand All @@ -207,15 +201,15 @@ test(
function () {
return global.NETWORK_TYPE !== networkTypes.WIFI;
},
function (t) {
tape.sinonTest(function (t) {
var wifiInfrastructure = new ThaliWifiInfrastructure();
var ssdpServer = wifiInfrastructure._getSSDPServer();
var ssdpClient = wifiInfrastructure._getSSDPClient();
var stubs = {
serverStart: sandbox.stub(ssdpServer, 'start', callArg),
serverStop: sandbox.stub(ssdpServer, 'stop', callArg),
clientStart: sandbox.stub(ssdpClient, 'start', callArg),
clientStop: sandbox.stub(ssdpClient, 'stop', callArg)
serverStart: this.stub(ssdpServer, 'start', callArg),
serverStop: this.stub(ssdpServer, 'stop', callArg),
clientStart: this.stub(ssdpClient, 'start', callArg),
clientStop: this.stub(ssdpClient, 'stop', callArg)
};
var context = { t: t, stubs: stubs };
var testBssid = testBssidChangeReaction.bind(null, context);
Expand Down Expand Up @@ -244,5 +238,5 @@ test(
'should not be in started state');
t.end();
});
}
})
);

0 comments on commit ea2ff16

Please sign in to comment.