logs.test.js
4.5 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
/*
*
* 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/test-helper/command-handler',
'screens/player/shared/csrf',
'screens/player/store/store',
'screens/player/firmware/log/logger',
'screens/player/command/command',
'screens/player/command/logs'
], function(ServiceAdmin, stubServiceInterface, serviceTestHelper, commandHandlerTestHelper, CSRFSupport, StoreSvc, LoggerSvc, PlayerCommand, logsCmd) {
'use strict';
describe('screens/player/command/logs', function() {
var stubCsrf, stubStoreService, stubLoggerService;
beforeEach(function() {
stubCsrf = sinon.stub(CSRFSupport.prototype);
stubStoreService = stubServiceInterface(ServiceAdmin, StoreSvc);
stubLoggerService = stubServiceInterface(ServiceAdmin, LoggerSvc);
});
afterEach(function() {
Object.keys(stubCsrf).forEach(function(k) {
stubCsrf[k].restore();
});
stubStoreService.restore();
stubLoggerService.restore();
});
serviceTestHelper.runDefaultTests(logsCmd, PlayerCommand.serviceName);
commandHandlerTestHelper.runDefaultTests(logsCmd, 'logs');
it('should collect the logs and send them to the server on the "logs" command', function(done) {
var ajaxPromise = Promise.resolve();
var listLogsPromise = Promise.resolve(['/log/file/foo', '/log/file/bar']);
var file1Promise = Promise.resolve({});
var file2Promise = Promise.resolve({});
stubCsrf.$ajax.returns(ajaxPromise);
stubStoreService.api.getState.returns({ statusmodel: { devicePostUrl: '/foo/bar/baz' } });
stubLoggerService.api.listLogs.returns(listLogsPromise);
stubLoggerService.api.getLogBlob.onFirstCall().returns(file1Promise);
stubLoggerService.api.getLogBlob.onSecondCall().returns(file2Promise);
logsCmd.handleCommand('logs');
listLogsPromise
.then(function() {
expect(stubLoggerService.api.listLogs).to.have.been.calledWith();
})
.then(Promise.all([file1Promise, file2Promise]))
.then(function() {
expect(stubLoggerService.api.getLogBlob.firstCall).to.have.been.calledWith('/log/file/foo');
expect(stubLoggerService.api.getLogBlob.secondCall).to.have.been.calledWith('/log/file/bar');
})
.then(ajaxPromise)
.then(function() {
expect(stubCsrf.$ajax).to.have.been.called;
done();
});
});
it('throws an error if the Store service is not available', function() {
ServiceAdmin.getService.withArgs(StoreSvc.serviceName).returns(null);
stubStoreService.api.getState.returns({ statusmodel: { devicePostUrl: '/foo/bar/baz' } });
expect(function() { logsCmd.handleCommand('logs'); }).to.throw();
ServiceAdmin.getService.restore();
});
it('throws an error if the Logger service is not available', function() {
ServiceAdmin.getService.withArgs(LoggerSvc.serviceName).returns(null);
stubStoreService.api.getState.returns({ statusmodel: { devicePostUrl: '/foo/bar/baz' } });
expect(function() { logsCmd.handleCommand('logs'); }).to.throw();
ServiceAdmin.getService.restore();
});
it('throws an error if the devicePostUrl is missing in the state', function() {
stubStoreService.api.getState.returns({});
expect(function() { logsCmd.handleCommand('logs'); }).to.throw();
});
});
});