@@ -137,4 +137,61 @@ describe("LifxLightService", () => {
137137 ) . rejects . toThrow ( new Error ( "Boom!" ) ) ;
138138 } ) ;
139139 } ) ;
140+
141+ describe ( "#disco" , ( ) => {
142+ it ( "calls the LIFX API with the color, cycles, period and lights" , async ( ) => {
143+ const driver = new FakeHttpDriver ( ) ;
144+ const subject = new LifxLightService ( driver ) ;
145+ const light = LightBuilder . build ( { service : "LIFX" } ) ;
146+
147+ await subject . disco ( light , { color : "red" , cycles : 5 , period : 5 } ) ;
148+
149+ expect ( driver . post ) . toHaveBeenCalledWith (
150+ `https://api.lifx.com/v1/lights/id:${ light . id } /effects/breathe` ,
151+ {
152+ payload : { color : "red" , cycles : 5 , period : 5 } ,
153+ headers : { Authorization : "Bearer fake-lifx-token" } ,
154+ }
155+ ) ;
156+ } ) ;
157+
158+ it ( "calls the LIFX API with the initialColor, color, cycles, period and lights" , async ( ) => {
159+ const driver = new FakeHttpDriver ( ) ;
160+ const subject = new LifxLightService ( driver ) ;
161+ const light = LightBuilder . build ( { service : "LIFX" } ) ;
162+
163+ await subject . disco ( light , {
164+ color : "red" ,
165+ cycles : 5 ,
166+ period : 5 ,
167+ initialColor : "blue" ,
168+ } ) ;
169+
170+ expect ( driver . post ) . toHaveBeenCalledWith (
171+ `https://api.lifx.com/v1/lights/id:${ light . id } /effects/breathe` ,
172+ {
173+ payload : { color : "red" , cycles : 5 , period : 5 , from_color : "blue" } ,
174+ headers : { Authorization : "Bearer fake-lifx-token" } ,
175+ }
176+ ) ;
177+ } ) ;
178+
179+ it ( "throws the error if the driver fails" , async ( ) => {
180+ const driver = new FakeHttpDriver ( ) ;
181+ driver . post . mockImplementation ( ( ) => {
182+ throw new Error ( "Boom!" ) ;
183+ } ) ;
184+ const light = LightBuilder . build ( { service : "LIFX" } ) ;
185+ const subject = new LifxLightService ( driver ) ;
186+
187+ await expect (
188+ subject . disco ( light , {
189+ color : "red" ,
190+ cycles : 5 ,
191+ period : 5 ,
192+ initialColor : "blue" ,
193+ } )
194+ ) . rejects . toThrow ( new Error ( "Boom!" ) ) ;
195+ } ) ;
196+ } ) ;
140197} ) ;
0 commit comments