UNPKG

3.14 kBJavaScriptView Raw
1"use strict";
2
3module.exports.mockLoggingService = function () {
4 return jasmine.createSpyObj('loggingService', ['error', 'debug', 'info', 'warn']);
5};
6
7module.exports.mockCyclonNode = function () {
8 return jasmine.createSpyObj('cyclonNode', ['getId', 'start', 'executeShuffle', 'createNewPointer', 'handleShuffleRequest', 'handleShuffleResponse', 'emit']);
9};
10
11module.exports.mockRtc = function () {
12 return jasmine.createSpyObj('rtc', ['connect', 'onChannel', 'openChannel', 'on', 'createNewPointer', 'getLocalId']);
13};
14
15module.exports.mockChannel = function() {
16 return jasmine.createSpyObj('channel', ['getRemotePeer', 'createOffer', 'createAnswer', 'sendAnswer', 'waitForChannelEstablishment', 'waitForIceCandidates', 'sendOffer', 'handleAnswer', 'waitForChannelToOpen', 'send', 'receive', 'close', 'cancel']);
17};
18
19module.exports.mockAsyncExecService = function () {
20 return jasmine.createSpyObj('asyncExecService', ['setTimeout', 'setInterval', 'clearTimeout', 'clearInterval']);
21};
22
23module.exports.mockSignallingSocket = function () {
24 return jasmine.createSpyObj('signallingSocket', ['getCurrentServerSpecs', 'initialize', 'on']);
25};
26
27module.exports.mockHttpRequestService = function () {
28 return jasmine.createSpyObj('httpRequestService', ['get', 'post']);
29};
30
31module.exports.mockShuffleStateFactory = function () {
32 return jasmine.createSpyObj('shuffleStateFactory', ['createOutgoingShuffleState', 'createIncomingShuffleState']);
33};
34
35module.exports.mockOutgoingShuffleState = function (name) {
36 return jasmine.createSpyObj(name || 'outgoingShuffleState', ['sendShuffleRequest', 'processShuffleResponse', 'sendResponseAcknowledgement', 'storeChannel', 'close', 'cancel']);
37};
38
39module.exports.mockIncomingShuffleState = function () {
40 return jasmine.createSpyObj('incomingShuffleState', ['processShuffleRequest', 'waitForResponseAcknowledgement', 'close', 'cancel']);
41};
42
43module.exports.mockNeighbourSet = function () {
44 return jasmine.createSpyObj('neighbourSet', ['contains', 'insert', 'remove', 'get', 'size', 'selectShuffleSet', 'findOldestId', 'randomSelection', 'incrementAges', 'resetAge', 'mergeNodePointerIfNewer']);
45};
46
47module.exports.mockComms = function () {
48 return jasmine.createSpyObj('comms', ['sendShuffleRequest', 'sendShuffleResponse', 'getPointerData']);
49};
50
51module.exports.mockStorage = function() {
52 return jasmine.createSpyObj('storage', ['getItem', 'setItem']);
53};
54
55//
56// Success/failure callbacks for testing
57//
58module.exports.createSuccessCallback = function () {
59 return jasmine.createSpy('successCallback');
60};
61
62module.exports.createFailureCallback = function () {
63 return jasmine.createSpy('failureCallback').and.callFake(function (error) {
64 //console.error("Error occurred!", error);
65 });
66};
67
68module.exports.mockPromise = function() {
69 var mockPromise = jasmine.createSpyObj('mockPromise', ['isPending', 'close', 'cancel', 'then', 'catch', 'cancellable']);
70 mockPromise.then.and.returnValue(mockPromise);
71 mockPromise.cancellable.and.returnValue(mockPromise);
72 mockPromise.catch.and.returnValue(mockPromise);
73 return mockPromise;
74};