update-service.test.js
6.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
/*
* ADOBE CONFIDENTIAL
* __________________
*
* Copyright 2016 Adobe Systems Incorporated
* All Rights Reserved.
*
* NOTICE: All information contained herein is, and remains
* the property of Adobe Systems Incorporated and its suppliers,
* if any. The intellectual and technical concepts contained
* herein are proprietary to Adobe Systems Incorporated and its
* suppliers and are protected by trade secret or copyright law.
* Dissemination of this information or reproduction of this material
* is strictly forbidden unless prior written permission is obtained
* from Adobe Systems Incorporated.
*/
/* eslint max-nested-callbacks: [2, 10]*/
/* eslint no-new: 0 */
/* globals describe, it, beforeEach, expect, afterEach, Promise */
define([
'screens/player/firmware/update/impl/update-service',
'screens/player/shared/serviceadmin',
'screens/player/firmware/preferences/preferences',
'screens/player/firmware/update/update',
'screens/player/firmware/update/spi/update',
'screens/player/store/store',
'screens/player/store/statemachine-adapter',
'screens/player/shared/test-helper/stub-service-interface',
'screens/player/shared/test-helper/mock-store-service'
], function(UpdateService, ServiceAdmin, Preferences, Update, UpdateSpi, Store, StateMachineAdapter, stubServiceInterface, mockStoreService) {
'use strict';
function createTransitionAction(prop) {
return {
type: StateMachineAdapter.EVENTS.CHANGE,
payload: { transitionTo: prop }
};
}
function createUpdateStoreState(state) {
return {
progress: state
};
}
function createSpiParams(serverUrl) {
return {
serverURL: serverUrl,
id: 'firmware',
idPrefix: '',
trustAllHosts: true,
requestHeaders: { 'X-Requested-With': 'XMLHttpRequest' }
};
}
describe('screens/player/firmware/update/impl/update-service', function() {
var updateService;
var mockedStoreService;
var stubUpdateSpiService;
beforeEach(function() {
mockedStoreService = mockStoreService(stubServiceInterface(ServiceAdmin, Store));
stubUpdateSpiService = stubServiceInterface(ServiceAdmin, UpdateSpi);
updateService = new UpdateService();
});
afterEach(function() {
mockedStoreService.restore();
stubUpdateSpiService.restore();
});
it('should have an id', function() {
expect(updateService.serviceId).to.be.ok;
});
describe('activation', function() {
it('returns a resolved Promise', function() {
return updateService.activate();
});
it('dispatches "undefined" action', function() {
return updateService.activate().then(function() {
expect(mockedStoreService.api.dispatch.calledWithMatch({
type: StateMachineAdapter.EVENTS.CHANGE,
payload: {
transitionTo: void 0
}
})).to.be.ok;
});
});
});
describe('API (after activation)', function() {
beforeEach(function() {
return updateService.activate().then(function() {
// Track events as of now. Ignore events that happened previously.
mockedStoreService.api.dispatch.reset();
mockedStoreService.publish(Preferences.NAMESPACE, { server: 'some server' });
});
});
describe('hasStepByStepSupport()', function() {
it('returns false when SPI returns false', function() {
stubUpdateSpiService.api.hasStepByStepSupport.returns(false);
expect(updateService.hasStepByStepSupport()).to.be.false;
});
it('returns true when SPI returns true', function() {
stubUpdateSpiService.api.hasStepByStepSupport.returns(true);
expect(updateService.hasStepByStepSupport()).to.be.true;
});
});
describe('update()', function() {
it('returns a Promise', function() {
expect(updateService.update()).to.be.an.instanceof(Promise);
});
it('rejects follow-up calls', function() {
updateService.update();
return updateService.update().catch(function(e) {
expect(e).to.eql('Update task still running.');
});
});
it('initially transitions to "check"', function() {
updateService.update();
expect(mockedStoreService.api.dispatch.calledWithMatch(createTransitionAction('check'))).to.be.ok;
});
it('handles "START" and calls UpdateSPIs "start" method', function() {
updateService.update();
stubUpdateSpiService.api.start.returns(Promise.resolve());
mockedStoreService.publish(Update.NAMESPACE, createUpdateStoreState(Update.STATES.START));
expect(stubUpdateSpiService.api.start.calledWithMatch(createSpiParams('some server'))).to.be.ok;
});
it('handles "START" and transitions to "ok" on success', function(done) {
var resolvedStart = Promise.resolve();
updateService.update();
mockedStoreService.api.dispatch.reset();
stubUpdateSpiService.api.start.returns(resolvedStart);
mockedStoreService.publish(Update.NAMESPACE, createUpdateStoreState(Update.STATES.START));
resolvedStart.then(function() {
expect(mockedStoreService.api.dispatch.calledWithMatch(createTransitionAction('ok'))).to.be.ok;
done();
});
});
it('handles "START" and transitions to "error" on failure', function(done) {
var rejectedStart = Promise.reject();
updateService.update();
mockedStoreService.api.dispatch.reset();
stubUpdateSpiService.api.start.returns(rejectedStart);
mockedStoreService.publish(Update.NAMESPACE, createUpdateStoreState(Update.STATES.START));
rejectedStart.catch(function() {
expect(mockedStoreService.api.dispatch.calledWithMatch(createTransitionAction('error'))).to.be.ok;
done();
});
});
});
});
});
});