|
| 1 | +import stc from "string-to-color"; |
| 2 | +import { FakeLightService } from "../../../src"; |
| 3 | +import { Disco } from "../../../src/useCases/rewards/Disco"; |
| 4 | +import { LightBuilder } from "../../builders/LightBuilder"; |
| 5 | +import { RewardBuilder } from "../../builders/RewardBuilder"; |
| 6 | + |
| 7 | +jest.mock("string-to-color", () => jest.fn(() => "#fefefe")); |
| 8 | + |
| 9 | +describe("Disco", () => { |
| 10 | + describe("#perform", () => { |
| 11 | + it("uses the reward message to generate the color for the disco mode", async () => { |
| 12 | + const lightService = new FakeLightService(); |
| 13 | + const subject = new Disco(lightService); |
| 14 | + const reward = RewardBuilder.build(); |
| 15 | + const lights = LightBuilder.buildList(1); |
| 16 | + |
| 17 | + await subject.perform({ reward, lights }); |
| 18 | + |
| 19 | + expect(stc).toHaveBeenCalledWith(reward.message); |
| 20 | + }); |
| 21 | + |
| 22 | + it("uses the reward date to generate the initialColor for the disco mode", async () => { |
| 23 | + const lightService = new FakeLightService(); |
| 24 | + const subject = new Disco(lightService); |
| 25 | + const reward = RewardBuilder.build(); |
| 26 | + const lights = LightBuilder.buildList(1); |
| 27 | + |
| 28 | + await subject.perform({ reward, lights }); |
| 29 | + |
| 30 | + expect(stc).toHaveBeenCalledWith(reward.date); |
| 31 | + }); |
| 32 | + |
| 33 | + it("uses light service to start the disco mode", async () => { |
| 34 | + const lightService = new FakeLightService(); |
| 35 | + const subject = new Disco(lightService); |
| 36 | + const reward = RewardBuilder.build(); |
| 37 | + const lights = LightBuilder.buildList(1); |
| 38 | + |
| 39 | + await subject.perform({ reward, lights }); |
| 40 | + |
| 41 | + expect(lightService.disco).toHaveBeenCalledWith(lights[0], { |
| 42 | + color: "#fefefe", |
| 43 | + initialColor: "#fefefe", |
| 44 | + cycles: 5, |
| 45 | + period: 20, |
| 46 | + }); |
| 47 | + }); |
| 48 | + }); |
| 49 | +}); |
0 commit comments