-
Notifications
You must be signed in to change notification settings - Fork 903
Commit
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,134 @@ | ||
import { expect } from "chai"; | ||
import { getLoginCredential, getTestDevices } from "../../appdistribution/options-parser-util"; | ||
import { FirebaseError } from "../../error"; | ||
|
||
describe.only("options-parser-util", () => { | ||
describe("getTestDevices", () => { | ||
it("parses a test device", () => { | ||
const optionValue = "model=modelname,version=123,orientation=landscape,locale=en_US"; | ||
|
||
const result = getTestDevices(optionValue, ""); | ||
|
||
expect(result).to.deep.equal([{ | ||
Check failure on line 12 in src/test/appdistro/options-parser-util.spec.ts GitHub Actions / lint (20)
Check failure on line 12 in src/test/appdistro/options-parser-util.spec.ts GitHub Actions / unit (18)
Check failure on line 12 in src/test/appdistro/options-parser-util.spec.ts GitHub Actions / unit (20)
|
||
model: "modelname", | ||
Check failure on line 13 in src/test/appdistro/options-parser-util.spec.ts GitHub Actions / lint (20)
Check failure on line 13 in src/test/appdistro/options-parser-util.spec.ts GitHub Actions / unit (18)
Check failure on line 13 in src/test/appdistro/options-parser-util.spec.ts GitHub Actions / unit (20)
|
||
version: "123", | ||
Check failure on line 14 in src/test/appdistro/options-parser-util.spec.ts GitHub Actions / lint (20)
Check failure on line 14 in src/test/appdistro/options-parser-util.spec.ts GitHub Actions / unit (18)
Check failure on line 14 in src/test/appdistro/options-parser-util.spec.ts GitHub Actions / unit (20)
|
||
orientation: "landscape", | ||
Check failure on line 15 in src/test/appdistro/options-parser-util.spec.ts GitHub Actions / lint (20)
Check failure on line 15 in src/test/appdistro/options-parser-util.spec.ts GitHub Actions / unit (18)
Check failure on line 15 in src/test/appdistro/options-parser-util.spec.ts GitHub Actions / unit (20)
|
||
locale: "en_US", | ||
Check failure on line 16 in src/test/appdistro/options-parser-util.spec.ts GitHub Actions / lint (20)
Check failure on line 16 in src/test/appdistro/options-parser-util.spec.ts GitHub Actions / unit (18)
Check failure on line 16 in src/test/appdistro/options-parser-util.spec.ts GitHub Actions / unit (20)
|
||
}]); | ||
Check failure on line 17 in src/test/appdistro/options-parser-util.spec.ts GitHub Actions / lint (20)
Check failure on line 17 in src/test/appdistro/options-parser-util.spec.ts GitHub Actions / unit (18)
Check failure on line 17 in src/test/appdistro/options-parser-util.spec.ts GitHub Actions / unit (20)
|
||
}); | ||
|
||
it("parses multiple semicolon-separated test devices", () => { | ||
const optionValue = | ||
"model=modelname,version=123,orientation=landscape,locale=en_US;model=modelname2,version=456,orientation=portrait,locale=es"; | ||
|
||
const result = getTestDevices(optionValue, ""); | ||
|
||
expect(result).to.deep.equal([ | ||
{ | ||
model: "modelname", | ||
version: "123", | ||
orientation: "landscape", | ||
locale: "en_US", | ||
}, | ||
{ | ||
model: "modelname2", | ||
version: "456", | ||
orientation: "portrait", | ||
locale: "es", | ||
} | ||
Check failure on line 38 in src/test/appdistro/options-parser-util.spec.ts GitHub Actions / lint (20)
Check failure on line 38 in src/test/appdistro/options-parser-util.spec.ts GitHub Actions / unit (18)
Check failure on line 38 in src/test/appdistro/options-parser-util.spec.ts GitHub Actions / unit (20)
|
||
]); | ||
}); | ||
|
||
it("parses multiple newline-separated test devices", () => { | ||
const optionValue = | ||
"model=modelname,version=123,orientation=landscape,locale=en_US\nmodel=modelname2,version=456,orientation=portrait,locale=es"; | ||
|
||
const result = getTestDevices(optionValue, ""); | ||
|
||
expect(result).to.deep.equal([ | ||
{ | ||
model: "modelname", | ||
version: "123", | ||
orientation: "landscape", | ||
locale: "en_US", | ||
}, | ||
{ | ||
model: "modelname2", | ||
version: "456", | ||
orientation: "portrait", | ||
locale: "es", | ||
} | ||
Check failure on line 60 in src/test/appdistro/options-parser-util.spec.ts GitHub Actions / lint (20)
Check failure on line 60 in src/test/appdistro/options-parser-util.spec.ts GitHub Actions / unit (18)
Check failure on line 60 in src/test/appdistro/options-parser-util.spec.ts GitHub Actions / unit (20)
|
||
]); | ||
}); | ||
|
||
it("throws an error with correct format when missing a field", () => { | ||
const optionValue = "model=modelname,version=123,locale=en_US"; | ||
|
||
expect(() => getTestDevices(optionValue, "")).to.throw( | ||
FirebaseError, | ||
"model=<model-id>,version=<os-version-id>,locale=<locale>,orientation=<orientation>", | ||
); | ||
}); | ||
|
||
it("throws an error with expected fields when field is unexpected", () => { | ||
const optionValue = "model=modelname,version=123,orientation=landscape,locale=en_US,notafield=blah"; | ||
Check failure on line 74 in src/test/appdistro/options-parser-util.spec.ts GitHub Actions / lint (20)
Check failure on line 74 in src/test/appdistro/options-parser-util.spec.ts GitHub Actions / unit (18)
Check failure on line 74 in src/test/appdistro/options-parser-util.spec.ts GitHub Actions / unit (20)
|
||
|
||
expect(() => getTestDevices(optionValue, "")).to.throw( | ||
FirebaseError, | ||
"model, version, orientation, locale", | ||
); | ||
}); | ||
}); | ||
|
||
describe("getLoginCredential", () => { | ||
it("returns credential for username and password", () => { | ||
const result = getLoginCredential("user", "123"); | ||
|
||
expect(result).to.deep.equal({ | ||
username: "user", | ||
password: "123", | ||
fieldHints: undefined, | ||
}); | ||
}); | ||
|
||
it("returns undefined when no options provided", () => { | ||
const result = getLoginCredential(); | ||
|
||
expect(result).to.be.undefined | ||
Check failure on line 97 in src/test/appdistro/options-parser-util.spec.ts GitHub Actions / lint (20)
Check failure on line 97 in src/test/appdistro/options-parser-util.spec.ts GitHub Actions / unit (18)
Check failure on line 97 in src/test/appdistro/options-parser-util.spec.ts GitHub Actions / unit (20)
|
||
}); | ||
|
||
it("returns credential for username, password, and resource names", () => { | ||
const result = getLoginCredential("user", "123", "username_resource_id", "password_resource_id"); | ||
|
||
expect(result).to.deep.equal({ | ||
username: "user", | ||
password: "123", | ||
fieldHints: { | ||
usernameResourceName: "username_resource_id", | ||
passwordResourceName: "password_resource_id", | ||
}, | ||
}); | ||
}); | ||
|
||
it("throws error when username and password not provided together", () => { | ||
expect(() => getLoginCredential("user", undefined)).to.throw( | ||
FirebaseError, | ||
"Username and password for automated tests need to be specified together" | ||
); | ||
}); | ||
|
||
it("throws error when username but not password resources not provided together", () => { | ||
expect(() => getLoginCredential("user", "123", undefined, "password_resource_id")).to.throw( | ||
FirebaseError, | ||
"Username and password resource names for automated tests need to be specified together" | ||
); | ||
}); | ||
|
||
it("throws error when resource names provided without username and password", () => { | ||
expect(() => getLoginCredential(undefined, undefined, "username_resource_id", "password_resource_id")).to.throw( | ||
FirebaseError, | ||
"Must specify username and password" | ||
); | ||
}); | ||
}); | ||
}); |