This repository has been archived by the owner on Mar 13, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathlib-deploy.spec.js
178 lines (139 loc) · 4.84 KB
/
lib-deploy.spec.js
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
169
170
171
172
173
174
175
176
177
178
'use strict';
describe('skyux-deploy lib deploy', () => {
const mock = require('mock-require');
const logger = require('@blackbaud/skyux-logger');
const distAsset = {
name: 'my-asset.js',
content: 'my-content',
};
const emittedAsset = {
name: 'my-image.png',
file: 'full-path/my-image.png',
};
let assetsMock;
let azureMock;
let deploySpaMock;
let deployStaticMock;
let lib;
beforeEach(() => {
spyOn(logger, 'error');
spyOn(logger, 'info');
azureMock = {
registerAssetsToBlob: jasmine
.createSpy('registerAssetsToBlob')
.and.returnValue(Promise.resolve()),
};
assetsMock = {
getDistAssets: jasmine
.createSpy('getDistAssets')
.and.returnValue([distAsset]),
getEmittedAssets: jasmine
.createSpy('getEmittedAssets')
.and.returnValue([emittedAsset]),
};
deploySpaMock = jasmine
.createSpy('deploySpa')
.and.returnValue(Promise.resolve());
deployStaticMock = jasmine
.createSpy('deployStatic')
.and.returnValue(Promise.resolve());
mock('../lib/azure', azureMock);
mock('../lib/assets', assetsMock);
mock('../lib/deploy-spa', deploySpaMock);
mock('../lib/deploy-static', deployStaticMock);
lib = mock.reRequire('../lib/deploy');
});
afterEach(() => {
mock.stopAll();
});
it('should call registerAssetsToBlob with the expected parameters', async () => {
await lib({
name: 'custom-name1',
version: 'custom-version1',
});
expect(azureMock.registerAssetsToBlob).toHaveBeenCalledWith(
{
name: 'custom-name1',
version: 'custom-version1',
},
[distAsset, emittedAsset]
);
});
it('should handle an error after calling registerEntityToBlob', async () => {
azureMock.registerAssetsToBlob.and.returnValue(
Promise.reject('custom-error1')
);
await expectAsync(lib({})).toBeRejectedWith('custom-error1');
expect(logger.error).toHaveBeenCalledWith('custom-error1');
});
it('should reject if there are no assets found', async () => {
const err = 'Unable to locate any assets to deploy.';
assetsMock.getDistAssets.and.returnValue([]);
assetsMock.getEmittedAssets.and.returnValue([]);
const result = lib({});
await expectAsync(result).toBeRejectedWithError(err);
expect(logger.error).toHaveBeenCalledWith(err);
});
it('should deploy when "deactivated: true" is found in skyuxconfig', async () => {
assetsMock.getDistAssets.and.returnValue([]);
assetsMock.getEmittedAssets.and.returnValue([]);
const settings = {
azureStorageAccessKey: 'MOCK_ACCESS_KEY',
name: 'my-app',
version: 'foobar',
skyuxConfig: { deactivated: true },
packageConfig: {},
};
await lib(settings);
expect(deploySpaMock).toHaveBeenCalledWith(settings);
});
describe('when isStaticClient = false', () => {
it('should call deploySpa if registerAssetsToBlob is successful', async () => {
const settings = {
azureStorageAccessKey: 'abc',
name: 'custom-name2',
version: 'custom-version2',
skyuxConfig: { test1: true },
packageConfig: { test2: true },
};
await lib(settings);
expect(deploySpaMock).toHaveBeenCalledWith(settings);
expect(deployStaticMock).not.toHaveBeenCalled();
});
it('should handle an error after calling deploySpa', async () => {
deploySpaMock.and.returnValue(Promise.reject('custom-error2'));
await expectAsync(lib({})).toBeRejectedWith('custom-error2');
expect(logger.error).toHaveBeenCalledWith('custom-error2');
});
it('should display a message if deploySpa is successful', async () => {
await lib({});
expect(logger.info).toHaveBeenCalledWith('Successfully registered.');
});
});
describe('when isStaticClient = true', () => {
it('should call deployStatic if registerAssetsToBlob is successful', async () => {
const settings = {
azureStorageAccessKey: 'abc',
name: 'custom-name2',
isStaticClient: true,
version: 'custom-version2',
skyuxConfig: { test1: true },
packageConfig: { test2: true },
};
await lib(settings);
expect(deployStaticMock).toHaveBeenCalledWith(settings);
expect(deploySpaMock).not.toHaveBeenCalled();
});
it('should handle an error after calling deployStatic', async () => {
deployStaticMock.and.returnValue(Promise.reject('custom-error2'));
await expectAsync(lib({ isStaticClient: true })).toBeRejectedWith(
'custom-error2'
);
expect(logger.error).toHaveBeenCalledWith('custom-error2');
});
it('should display a message if deploySpa is successful', async () => {
await lib({ isStaticClient: true });
expect(logger.info).toHaveBeenCalledWith('Successfully registered.');
});
});
});