setBrush.test.ts 1.77 KB
import { expect } from "chai";
import { clear } from "./util/clear";
import { prepareGame } from "./util/prepare";

describe("라운드 브러시 설정", () => {
  it("drawer가 브러시를 설정하면 다른 사람들이 설정을 받습니다", () => {
    const { drawerSocket, guesserSockets, room } = prepareGame(2);

    const brushSettings = {
      size: 1,
      color: "000000",
      drawing: true,
    };
    drawerSocket.testOk("setBrush", brushSettings);
    expect(guesserSockets[0].socket.received("setBrush")).deep.eq(
      brushSettings
    );

    clear([room]);
  });
  it("올바르지 않은 브러시 색상은 허용되지 않습니다", () => {
    const { drawerSocket, room } = prepareGame(2);
    drawerSocket.testNotOk("setBrush", {
      size: 1,
      color: "000",
      drawing: true,
    });
    drawerSocket.testNotOk("setBrush", {
      size: 1,
      color: "asdf01",
      drawing: true,
    });

    clear([room]);
  });
  it("올바르지 않은 브러시 사이즈는 Clamp 됩니다", () => {
    const { drawerSocket, guesserSockets, room } = prepareGame(2);
    drawerSocket.testOk("setBrush", {
      size: 0,
      color: "000000",
      drawing: true,
    });
    expect(guesserSockets[0].socket.received("setBrush").size).eq(1);
    drawerSocket.testOk("setBrush", {
      size: 100,
      color: "000000",
      drawing: true,
    });
    expect(guesserSockets[0].socket.received("setBrush").size).eq(64);

    clear([room]);
  });
  it("drawer가 아닌 다른 사람들은 브러시를 설정할 수 없습니다", () => {
    const { guesserSockets, room } = prepareGame(2);

    const brushSettings = {
      size: 1,
      color: "000000",
      drawing: true,
    };
    guesserSockets[0].testNotOk("setBrush", brushSettings);

    clear([room]);
  });
});