-
-
Notifications
You must be signed in to change notification settings - Fork 197
/
Copy pathtns-appstore-upload.ts
186 lines (164 loc) · 5.67 KB
/
tns-appstore-upload.ts
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
179
180
181
182
183
184
185
186
import { PublishIOS } from "../lib/commands/appstore-upload";
import { PrompterStub, LoggerStub, ProjectDataStub, ProjectDataService } from "./stubs";
import * as chai from "chai";
import * as yok from "../lib/common/yok";
import { PrepareNativePlatformService } from "../lib/services/platform/prepare-native-platform-service";
import { BuildController } from "../lib/controllers/build-controller";
import { IOSBuildData } from "../lib/data/build-data";
class AppStore {
static itunesconnect = {
user: "[email protected]",
pass: "god"
};
// Services
injector: IInjector;
command: ICommand;
options: any;
prompter: PrompterStub;
projectData: ProjectDataStub;
buildController: BuildController;
prepareNativePlatformService: PrepareNativePlatformService;
platformCommandHelper: any;
platformValidationService: any;
iOSPlatformData: any;
iOSProjectService: any;
loggerService: LoggerStub;
itmsTransporterService: any;
// Counters
preparePlatformCalls: number = 0;
archiveCalls: number = 0;
expectedArchiveCalls: number = 0;
exportArchiveCalls: number = 0;
itmsTransporterServiceUploadCalls: number = 0;
expectedItmsTransporterServiceUploadCalls: number = 0;
before() {
this.iOSPlatformData = {
"projectRoot": "/Users/person/git/MyProject"
};
this.initInjector({
commands: {
"appstore": PublishIOS
},
services: {
"errors": {},
"fs": {},
"hostInfo": {},
"itmsTransporterService": this.itmsTransporterService = {},
"logger": this.loggerService = new LoggerStub(),
"options": this.options = {},
"prompter": this.prompter = new PrompterStub(),
"projectData": this.projectData = new ProjectDataStub(),
"stringParameterBuilder": {},
"devicePlatformsConstants": {
"iOS": "iOS"
},
"prepareNativePlatformService": this.prepareNativePlatformService = <any>{},
"platformCommandHelper": this.platformCommandHelper = {},
"platformValidationService": this.platformValidationService = {},
"buildController": this.buildController = <any>{
buildPlatform: async () => {
this.archiveCalls++;
return "/Users/person/git/MyProject/platforms/ios/archive/MyProject.ipa";
}
},
"platformsDataService": {
getPlatformData: (platform: string) => {
chai.assert.equal(platform, "iOS");
return this.iOSPlatformData;
}
},
"applePortalSessionService": {
createUserSession: () => {
return {
areCredentialsValid: true
};
}
}
}
});
this.projectData.initializeProjectData(this.iOSPlatformData.projectRoot);
this.command = this.injector.resolveCommand("appstore");
}
initInjector(services?: { commands?: { [service: string]: any }, services?: { [service: string]: any } }) {
this.injector = new yok.Yok();
if (services) {
for (const cmd in services.commands) {
this.injector.registerCommand(cmd, services.commands[cmd]);
}
for (const serv in services.services) {
this.injector.register(serv, services.services[serv]);
}
}
this.injector.register("projectDataService", ProjectDataService);
}
assert() {
this.prompter.assert();
chai.assert.equal(this.archiveCalls, this.expectedArchiveCalls, "Mismatched number of iOSProjectService.archive calls.");
chai.assert.equal(this.itmsTransporterServiceUploadCalls, this.expectedItmsTransporterServiceUploadCalls, "Mismatched number of itmsTransporterService.upload calls.");
}
expectItunesPrompt() {
this.prompter.expect({
strings: { "Apple ID": AppStore.itunesconnect.user },
passwords: { "Apple ID password": AppStore.itunesconnect.pass },
});
}
expectArchive() {
this.expectedArchiveCalls = 1;
this.buildController.prepareAndBuild = (iOSBuildData: IOSBuildData) => {
this.archiveCalls++;
chai.assert.equal(iOSBuildData.projectDir, "/Users/person/git/MyProject");
chai.assert.isTrue(iOSBuildData.buildForAppStore);
return Promise.resolve("/Users/person/git/MyProject/platforms/ios/archive/MyProject.ipa");
};
}
expectITMSTransporterUpload() {
this.expectedItmsTransporterServiceUploadCalls = 1;
this.itmsTransporterService.validate = () => Promise.resolve();
this.itmsTransporterService.upload = (options: IITMSData) => {
this.itmsTransporterServiceUploadCalls++;
chai.assert.equal(options.ipaFilePath, "/Users/person/git/MyProject/platforms/ios/archive/MyProject.ipa");
chai.assert.equal(options.credentials.username, AppStore.itunesconnect.user);
chai.assert.equal(options.credentials.password, AppStore.itunesconnect.pass);
chai.assert.equal(options.verboseLogging, false);
return Promise.resolve();
};
}
async noArgs() {
this.expectItunesPrompt();
this.expectArchive();
this.expectITMSTransporterUpload();
await this.command.execute([]);
this.assert();
}
async itunesconnectArgs() {
this.expectArchive();
this.expectITMSTransporterUpload();
await this.command.execute([AppStore.itunesconnect.user, AppStore.itunesconnect.pass]);
this.assert();
}
async teamIdOption() {
this.expectItunesPrompt();
this.expectArchive();
this.expectITMSTransporterUpload();
this.options.teamId = "MyTeamID";
await this.command.execute([]);
this.assert();
}
}
describe("tns appstore", () => {
it("without args, prompts for itunesconnect credentionals, prepares, archives and uploads", async () => {
const instance = new AppStore();
instance.before();
await instance.noArgs();
});
it("with command line itunesconnect credentionals, prepares, archives and uploads", async () => {
const instance = new AppStore();
instance.before();
await instance.itunesconnectArgs();
});
it("passes --team-id to xcodebuild exportArchive", async () => {
const instance = new AppStore();
instance.before();
await instance.teamIdOption();
});
});