statusinfo-service.test.js
3.42 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
/*
*
* 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.
*/
/* globals Promise, sinon, describe, it, beforeEach, afterEach, expect */
/* eslint max-nested-callbacks: 0 */
define([
'screens/player/shared/serviceadmin',
'screens/player/shared/test-helper/stub-service-interface',
'screens/player/shared/test-helper/service',
'screens/player/shared/csrf',
'screens/player/firmware/statusinfo/statusinfo',
'screens/player/store/store',
'screens/player/firmware/storage/storage',
'screens/player/firmware/statusinfo/impl/statusinfo-service'
], function(ServiceAdmin, stubServiceInterface, serviceTestHelper, CSRFSupport, StatusInfo, Store, Storage, StatusInfoService) {
'use strict';
describe('StatusInfo', function() {
var stubCsrf, stubStoreService, stubStorageService;
beforeEach(function() {
stubCsrf = sinon.stub(CSRFSupport.prototype);
stubStoreService = stubServiceInterface(ServiceAdmin, Store);
stubStorageService = stubServiceInterface(ServiceAdmin, Storage);
stubStoreService.api.getState.returns({ statusmodel: { devicePostUrl: '/foo/bar/baz', version: '1.1.1' } });
stubStorageService.api.refresh.returns(Promise.resolve({some: 'storage'}));
});
afterEach(function() {
Object.keys(stubCsrf).forEach(function(k) {
stubCsrf[k].restore();
});
stubStoreService.restore();
stubStorageService.restore();
});
serviceTestHelper.runDefaultTests(StatusInfoService, StatusInfo.serviceName);
describe('send action', function() {
it('should send the status information', function() {
var dateStub = new Date();
var clock = sinon.useFakeTimers(dateStub.getTime()); // there is some bug in Sinon that turns the timestamp to 0
stubCsrf.$ajax.yieldsTo('success');
return StatusInfoService.send().then(function() {
expect(stubCsrf.$ajax).calledWithMatch(sinon.match.defined, {
url: '/foo/bar/baz.statusinfo.json',
type: 'POST',
data: { data: JSON.stringify({
usage: {},
timestamp: 0,
startTimestamp: 0,
firmwareVersion: '1.1.1'
}) }
});
clock.restore();
});
});
it('rejects if the devicePostUrl is missing in the state', function() {
stubStoreService.api.getState.returns({});
return StatusInfoService.send().catch(function(error) {
expect(error.message).to.equal('unable to send status information. no device url.');
});
});
});
});
});