Skip to content

Commit d7f9b3d

Browse files
keerthanakumarBryan Smith
authored andcommitted
Add test for mandatory flag in release
1 parent cb0a1e1 commit d7f9b3d

File tree

2 files changed

+143
-0
lines changed

2 files changed

+143
-0
lines changed

Tasks/AppCenterDistributeV1/Tests/L0.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,4 +165,14 @@ describe('AppCenterDistribute L0 Suite', function () {
165165
tr.run();
166166
assert(tr.succeeded, 'task should have succeeded');
167167
});
168+
169+
it('Positive path: publish mandatory update)', function () {
170+
this.timeout(4000);
171+
172+
let tp = path.join(__dirname, 'L0PublishMandatoryUpdate.js');
173+
let tr: ttm.MockTestRunner = new ttm.MockTestRunner(tp);
174+
175+
tr.run();
176+
assert(tr.succeeded, 'task should have succeeded');
177+
});
168178
});
Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
2+
import ma = require('vsts-task-lib/mock-answer');
3+
import tmrm = require('vsts-task-lib/mock-run');
4+
import path = require('path');
5+
import fs = require('fs');
6+
var Readable = require('stream').Readable
7+
var Stats = require('fs').Stats
8+
9+
var nock = require('nock');
10+
11+
let taskPath = path.join(__dirname, '..', 'appcenterdistribute.js');
12+
let tmr: tmrm.TaskMockRunner = new tmrm.TaskMockRunner(taskPath);
13+
14+
tmr.setInput('serverEndpoint', 'MyTestEndpoint');
15+
tmr.setInput('appSlug', 'testuser/testapp');
16+
tmr.setInput('app', '/test/path/to/my.ipa');
17+
tmr.setInput('releaseNotesSelection', 'releaseNotesInput');
18+
tmr.setInput('releaseNotesInput', 'my release notes');
19+
tmr.setInput('isMandatory', 'True');
20+
tmr.setInput('symbolsType', 'AndroidJava');
21+
tmr.setInput('mappingTxtPath', '/test/path/to/mappings.txt');
22+
23+
process.env['BUILD_BUILDID'] = '2';
24+
process.env['BUILD_SOURCEBRANCHNAME'] = 'master';
25+
process.env['BUILD_SOURCEVERSION'] = 'commitsha';
26+
27+
//prepare upload
28+
nock('https://example.test')
29+
.post('/v0.1/apps/testuser/testapp/release_uploads')
30+
.reply(201, {
31+
upload_id: 1,
32+
upload_url: 'https://example.upload.test/release_upload'
33+
});
34+
35+
//upload
36+
nock('https://example.upload.test')
37+
.post('/release_upload')
38+
.reply(201, {
39+
status: 'success'
40+
});
41+
42+
//finishing upload, commit the package
43+
nock('https://example.test')
44+
.patch("/v0.1/apps/testuser/testapp/release_uploads/1", {
45+
status: 'committed'
46+
})
47+
.reply(200, {
48+
release_url: 'my_release_location'
49+
});
50+
51+
//make it available
52+
//JSON.stringify to verify exact match of request body: https://github.com/node-nock/nock/issues/571
53+
nock('https://example.test')
54+
.patch("/my_release_location", JSON.stringify({
55+
status: "available",
56+
release_notes: "my release notes",
57+
mandatory_update: true,
58+
destinations: [{ id: "00000000-0000-0000-0000-000000000000" }],
59+
build: {
60+
id: '2',
61+
branch: 'master',
62+
commit_hash: 'commitsha'
63+
}
64+
}))
65+
.reply(200);
66+
67+
//begin symbol upload
68+
nock('https://example.test')
69+
.post('/v0.1/apps/testuser/testapp/symbol_uploads', {
70+
symbol_type: "AndroidJava"
71+
})
72+
.reply(201, {
73+
symbol_upload_id: 100,
74+
upload_url: 'https://example.upload.test/symbol_upload',
75+
expiration_date: 1234567
76+
});
77+
78+
//upload symbols
79+
nock('https://example.upload.test')
80+
.put('/symbol_upload')
81+
.reply(201, {
82+
status: 'success'
83+
});
84+
85+
//finishing symbol upload, commit the symbol
86+
nock('https://example.test')
87+
.patch("/v0.1/apps/testuser/testapp/symbol_uploads/100", {
88+
status: 'committed'
89+
})
90+
.reply(200);
91+
92+
// provide answers for task mock
93+
let a: ma.TaskLibAnswers = <ma.TaskLibAnswers>{
94+
"checkPath" : {
95+
"/test/path/to/my.ipa": true,
96+
"/test/path/to/mappings.txt": true
97+
},
98+
"findMatch" : {
99+
"/test/path/to/mappings.txt": [
100+
"/test/path/to/mappings.txt"
101+
],
102+
"/test/path/to/my.ipa": [
103+
"/test/path/to/my.ipa"
104+
]
105+
}
106+
};
107+
tmr.setAnswers(a);
108+
109+
fs.createReadStream = (s: string) => {
110+
let stream = new Readable;
111+
stream.push(s);
112+
stream.push(null);
113+
114+
return stream;
115+
};
116+
117+
fs.statSync = (s: string) => {
118+
let stat = new Stats;
119+
120+
stat.isFile = () => {
121+
return !s.toLowerCase().endsWith(".dsym");
122+
}
123+
stat.isDirectory = () => {
124+
return s.toLowerCase().endsWith(".dsym");
125+
}
126+
stat.size = 100;
127+
128+
return stat;
129+
}
130+
tmr.registerMock('fs', fs);
131+
132+
tmr.run();
133+

0 commit comments

Comments
 (0)