1+ import { expect } from "chai" ;
2+ import { getLoginCredential , getTestDevices } from "../../appdistribution/options-parser-util" ;
3+ import { FirebaseError } from "../../error" ;
4+
5+ describe . only ( "options-parser-util" , ( ) => {
6+ describe ( "getTestDevices" , ( ) => {
7+ it ( "parses a test device" , ( ) => {
8+ const optionValue = "model=modelname,version=123,orientation=landscape,locale=en_US" ;
9+
10+ const result = getTestDevices ( optionValue , "" ) ;
11+
12+ expect ( result ) . to . deep . equal ( [ {
13+ model : "modelname" ,
14+ version : "123" ,
15+ orientation : "landscape" ,
16+ locale : "en_US" ,
17+ } ] ) ;
18+ } ) ;
19+
20+ it ( "parses multiple semicolon-separated test devices" , ( ) => {
21+ const optionValue =
22+ "model=modelname,version=123,orientation=landscape,locale=en_US;model=modelname2,version=456,orientation=portrait,locale=es" ;
23+
24+ const result = getTestDevices ( optionValue , "" ) ;
25+
26+ expect ( result ) . to . deep . equal ( [
27+ {
28+ model : "modelname" ,
29+ version : "123" ,
30+ orientation : "landscape" ,
31+ locale : "en_US" ,
32+ } ,
33+ {
34+ model : "modelname2" ,
35+ version : "456" ,
36+ orientation : "portrait" ,
37+ locale : "es" ,
38+ }
39+ ] ) ;
40+ } ) ;
41+
42+ it ( "parses multiple newline-separated test devices" , ( ) => {
43+ const optionValue =
44+ "model=modelname,version=123,orientation=landscape,locale=en_US\nmodel=modelname2,version=456,orientation=portrait,locale=es" ;
45+
46+ const result = getTestDevices ( optionValue , "" ) ;
47+
48+ expect ( result ) . to . deep . equal ( [
49+ {
50+ model : "modelname" ,
51+ version : "123" ,
52+ orientation : "landscape" ,
53+ locale : "en_US" ,
54+ } ,
55+ {
56+ model : "modelname2" ,
57+ version : "456" ,
58+ orientation : "portrait" ,
59+ locale : "es" ,
60+ }
61+ ] ) ;
62+ } ) ;
63+
64+ it ( "throws an error with correct format when missing a field" , ( ) => {
65+ const optionValue = "model=modelname,version=123,locale=en_US" ;
66+
67+ expect ( ( ) => getTestDevices ( optionValue , "" ) ) . to . throw (
68+ FirebaseError ,
69+ "model=<model-id>,version=<os-version-id>,locale=<locale>,orientation=<orientation>" ,
70+ ) ;
71+ } ) ;
72+
73+ it ( "throws an error with expected fields when field is unexpected" , ( ) => {
74+ const optionValue = "model=modelname,version=123,orientation=landscape,locale=en_US,notafield=blah" ;
75+
76+ expect ( ( ) => getTestDevices ( optionValue , "" ) ) . to . throw (
77+ FirebaseError ,
78+ "model, version, orientation, locale" ,
79+ ) ;
80+ } ) ;
81+ } ) ;
82+
83+ describe ( "getLoginCredential" , ( ) => {
84+ it ( "returns credential for username and password" , ( ) => {
85+ const result = getLoginCredential ( "user" , "123" ) ;
86+
87+ expect ( result ) . to . deep . equal ( {
88+ username : "user" ,
89+ password : "123" ,
90+ fieldHints : undefined ,
91+ } ) ;
92+ } ) ;
93+
94+ it ( "returns undefined when no options provided" , ( ) => {
95+ const result = getLoginCredential ( ) ;
96+
97+ expect ( result ) . to . be . undefined
98+ } ) ;
99+
100+ it ( "returns credential for username, password, and resource names" , ( ) => {
101+ const result = getLoginCredential ( "user" , "123" , "username_resource_id" , "password_resource_id" ) ;
102+
103+ expect ( result ) . to . deep . equal ( {
104+ username : "user" ,
105+ password : "123" ,
106+ fieldHints : {
107+ usernameResourceName : "username_resource_id" ,
108+ passwordResourceName : "password_resource_id" ,
109+ } ,
110+ } ) ;
111+ } ) ;
112+
113+ it ( "throws error when username and password not provided together" , ( ) => {
114+ expect ( ( ) => getLoginCredential ( "user" , undefined ) ) . to . throw (
115+ FirebaseError ,
116+ "Username and password for automated tests need to be specified together"
117+ ) ;
118+ } ) ;
119+
120+ it ( "throws error when username but not password resources not provided together" , ( ) => {
121+ expect ( ( ) => getLoginCredential ( "user" , "123" , undefined , "password_resource_id" ) ) . to . throw (
122+ FirebaseError ,
123+ "Username and password resource names for automated tests need to be specified together"
124+ ) ;
125+ } ) ;
126+
127+ it ( "throws error when resource names provided without username and password" , ( ) => {
128+ expect ( ( ) => getLoginCredential ( undefined , undefined , "username_resource_id" , "password_resource_id" ) ) . to . throw (
129+ FirebaseError ,
130+ "Must specify username and password"
131+ ) ;
132+ } ) ;
133+ } ) ;
134+ } ) ;
0 commit comments