|
| 1 | +import { Yok } from "../../../lib/common/yok"; |
| 2 | +import { ExportOptionsPlistService } from "../../../lib/services/ios/export-options-plist-service"; |
| 3 | +import { assert } from "chai"; |
| 4 | +import { EOL } from "os"; |
| 5 | + |
| 6 | +let actualPlistTemplate: string = null; |
| 7 | +const projectName = "myProjectName"; |
| 8 | +const projectRoot = "/my/test/project/platforms/ios"; |
| 9 | +const archivePath = "/my/test/archive/path"; |
| 10 | + |
| 11 | +function createTestInjector() { |
| 12 | + const injector = new Yok(); |
| 13 | + injector.register("fs", { |
| 14 | + writeFile: (exportPath: string, plistTemplate: string) => { |
| 15 | + actualPlistTemplate = plistTemplate; |
| 16 | + } |
| 17 | + }); |
| 18 | + injector.register("exportOptionsPlistService", ExportOptionsPlistService); |
| 19 | + |
| 20 | + return injector; |
| 21 | +} |
| 22 | + |
| 23 | +describe("ExportOptionsPlistService", () => { |
| 24 | + describe("createDevelopmentExportOptionsPlist", () => { |
| 25 | + const testCases = [ |
| 26 | + { |
| 27 | + name: "should create default export options plist", |
| 28 | + buildConfig: {} |
| 29 | + }, |
| 30 | + { |
| 31 | + name: "should create export options plist with provision", |
| 32 | + buildConfig: { provision: "myTestProvision" }, |
| 33 | + expectedPlist: "<key>provisioningProfiles</key> <dict> <key>org.nativescript.myTestApp</key> <string>myTestProvision</string> </dict>" |
| 34 | + }, |
| 35 | + { |
| 36 | + name: "should create export options plist with mobileProvisionIdentifier", |
| 37 | + buildConfig: { mobileProvisionIdentifier: "myTestProvision" }, |
| 38 | + expectedPlist: "<key>provisioningProfiles</key> <dict> <key>org.nativescript.myTestApp</key> <string>myTestProvision</string> </dict>" |
| 39 | + } |
| 40 | + ]; |
| 41 | + |
| 42 | + _.each(testCases, testCase => { |
| 43 | + _.each(["Development", "AdHoc", "Distribution", "Enterprise"], provisionType => { |
| 44 | + it(testCase.name, () => { |
| 45 | + const injector = createTestInjector(); |
| 46 | + const exportOptionsPlistService = injector.resolve("exportOptionsPlistService"); |
| 47 | + exportOptionsPlistService.getExportOptionsMethod = () => provisionType; |
| 48 | + |
| 49 | + const projectData = { projectName, projectIdentifiers: { ios: "org.nativescript.myTestApp" }}; |
| 50 | + exportOptionsPlistService.createDevelopmentExportOptionsPlist(archivePath, projectData, testCase.buildConfig); |
| 51 | + |
| 52 | + const template = actualPlistTemplate.split(EOL).join(" "); |
| 53 | + assert.isTrue(template.indexOf(`<key>method</key> <string>${provisionType}</string>`) > 0); |
| 54 | + assert.isTrue(template.indexOf("<key>uploadBitcode</key> <false/>") > 0); |
| 55 | + assert.isTrue(template.indexOf("<key>compileBitcode</key> <false/>") > 0); |
| 56 | + if (testCase.expectedPlist) { |
| 57 | + assert.isTrue(template.indexOf(testCase.expectedPlist) > 0); |
| 58 | + } |
| 59 | + }); |
| 60 | + }); |
| 61 | + }); |
| 62 | + }); |
| 63 | + describe("createDistributionExportOptionsPlist", () => { |
| 64 | + const testCases = [ |
| 65 | + { |
| 66 | + name: "should create default export options plist", |
| 67 | + buildConfig: {} |
| 68 | + }, |
| 69 | + { |
| 70 | + name: "should create export options plist with provision", |
| 71 | + buildConfig: { provision: "myTestProvision" }, |
| 72 | + expectedPlist: "<key>provisioningProfiles</key> <dict> <key>org.nativescript.myTestApp</key> <string>myTestProvision</string> </dict>" |
| 73 | + }, |
| 74 | + { |
| 75 | + name: "should create export options plist with mobileProvisionIdentifier", |
| 76 | + buildConfig: { mobileProvisionIdentifier: "myTestProvision" }, |
| 77 | + expectedPlist: "<key>provisioningProfiles</key> <dict> <key>org.nativescript.myTestApp</key> <string>myTestProvision</string> </dict>" |
| 78 | + }, |
| 79 | + { |
| 80 | + name: "should create export options plist with teamID", |
| 81 | + buildConfig: { teamId: "myTeamId" }, |
| 82 | + expectedPlist: "<key>teamID</key> <string>myTeamId</string>" |
| 83 | + } |
| 84 | + ]; |
| 85 | + |
| 86 | + _.each(testCases, testCase => { |
| 87 | + it(testCase.name, () => { |
| 88 | + const injector = createTestInjector(); |
| 89 | + const exportOptionsPlistService = injector.resolve("exportOptionsPlistService"); |
| 90 | + exportOptionsPlistService.getExportOptionsMethod = () => "app-store"; |
| 91 | + |
| 92 | + const projectData = { projectName, projectIdentifiers: { ios: "org.nativescript.myTestApp" }}; |
| 93 | + exportOptionsPlistService.createDistributionExportOptionsPlist(projectRoot, projectData, testCase.buildConfig); |
| 94 | + |
| 95 | + const template = actualPlistTemplate.split(EOL).join(" "); |
| 96 | + assert.isTrue(template.indexOf("<key>method</key> <string>app-store</string>") > 0); |
| 97 | + assert.isTrue(template.indexOf("<key>uploadBitcode</key> <false/>") > 0); |
| 98 | + assert.isTrue(template.indexOf("<key>compileBitcode</key> <false/>") > 0); |
| 99 | + assert.isTrue(template.indexOf("<key>uploadSymbols</key> <false/>") > 0); |
| 100 | + if (testCase.expectedPlist) { |
| 101 | + assert.isTrue(template.indexOf(testCase.expectedPlist) > 0); |
| 102 | + } |
| 103 | + }); |
| 104 | + }); |
| 105 | + }); |
| 106 | +}); |
0 commit comments