<commit_before>/* tslint:disable:no-empty */

import "hap-nodejs"
import * as hap from "hap-nodejs"
import * as sinon from "sinon"
import { Config } from "./../config"
import { Accessory, AccessoryConstructor, Homebridge } from "./../homebridge"

describe("public interface", () => {
  let homebridge: Homebridge

  beforeEach(() => {
    homebridge = {
      hap,
      log: {
        debug(...message: string[]): void {},
        info(...message: string[]): void {},
        warn(...message: string[]): void {},
        error(...message: string[]): void {},
      },
      registerAccessory(
        pluginName: string,
        accessoryName: string,
        constructor: AccessoryConstructor
      ) {},
    }
  })

  it("should call registerAccessory once", async () => {
    const mock = sinon.mock(homebridge)
    mock.expects("registerAccessory").once()

    const defaultExport = (await import("../index")) as (
      homebridge: Homebridge
    ) => void
    defaultExport(homebridge)

    mock.verify()
  })

  describe("registered accessory constructor", () => {
    let accessory: Accessory
    let config: Config

    beforeEach(async () => {
      const defaultExport = (await import("../index")) as (
        homebridge: Homebridge
      ) => void
      homebridge.registerAccessory = (
        pluginName: string,
        accessoryName: string,
        constructor: AccessoryConstructor
      ) => {
        accessory = new constructor(homebridge.log, config)
      }
      defaultExport(homebridge)
    })

    describe("with a default config", () => {
      let Service: HAPNodeJS.Service
      let services: HAPNodeJS.Service[]

      beforeAll(() => {
        config = {
          name: "Test Computer Speakers",
        }
      })

      beforeEach(() => {
        Service = hap.Service
        services = accessory.getServices()
      })

      it("should register a single service", () => {
        expect(services.length).toBe(1)
      })

      it("should register a lighbulb service", () => {
        expect(services[0].UUID).toStrictEqual(
          new Service.Lightbulb("test", "test").UUID
        )
      })

      it("should use the name provided in the config", () => {
        expect(services[0].displayName).toStrictEqual(config.name)
      })
    })
  })
})<commit_msg>Replace use of `Service` with `hap.Service`<commit_after>/* tslint:disable:no-empty */

import "hap-nodejs"
import * as hap from "hap-nodejs"
import * as sinon from "sinon"
import { Config } from "./../config"
import { Accessory, AccessoryConstructor, Homebridge } from "./../homebridge"

describe("public interface", () => {
  let homebridge: Homebridge

  beforeEach(() => {
    homebridge = {
      hap,
      log: {
        debug(...message: string[]): void {},
        info(...message: string[]): void {},
        warn(...message: string[]): void {},
        error(...message: string[]): void {},
      },
      registerAccessory(
        pluginName: string,
        accessoryName: string,
        constructor: AccessoryConstructor
      ) {},
    }
  })

  it("should call registerAccessory once", async () => {
    const mock = sinon.mock(homebridge)
    mock.expects("registerAccessory").once()

    const defaultExport = (await import("../index")) as (
      homebridge: Homebridge
    ) => void
    defaultExport(homebridge)

    mock.verify()
  })

  describe("registered accessory constructor", () => {
    let accessory: Accessory
    let config: Config

    beforeEach(async () => {
      const defaultExport = (await import("../index")) as (
        homebridge: Homebridge
      ) => void
      homebridge.registerAccessory = (
        pluginName: string,
        accessoryName: string,
        constructor: AccessoryConstructor
      ) => {
        accessory = new constructor(homebridge.log, config)
      }
      defaultExport(homebridge)
    })

    describe("with a default config", () => {
      let services: HAPNodeJS.Service[]

      beforeAll(() => {
        config = {
          name: "Test Computer Speakers",
        }
      })

      beforeEach(() => {
        services = accessory.getServices()
      })

      it("should register a single service", () => {
        expect(services.length).toBe(1)
      })

      it("should register a lighbulb service", () => {
        expect(services[0].UUID).toStrictEqual(
          new hap.Service.Lightbulb("test", "test").UUID
        )
      })

      it("should use the name provided in the config", () => {
        expect(services[0].displayName).toStrictEqual(config.name)
      })
    })
  })
})
{'fraction_non_alphanumeric': 0.1473224043715847, 'fraction_numerical': 0.0013114754098360656, 'mean_word_length': 2.369661266568483, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 31, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '774914', 'n_tokens_mistral': 1313, 'n_tokens_neox': 1286, 'n_words': 292}