-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
54bddc0
commit 98f8936
Showing
5 changed files
with
97 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import { BP35Connector } from "@/connector/BP35Connector"; | ||
import createWiSunConnector from "@/connector/WiSunConnector"; | ||
import { WiSunConnectorModel } from "@/connector/WiSunConnectorModel"; | ||
|
||
jest.mock("@/connector/BP35Connector"); | ||
|
||
describe("createWiSunConnector", () => { | ||
test("side指定ありモデルのインスタンスを取得できる", () => { | ||
const MockBP35Connector = jest.mocked(BP35Connector, { shallow: true }); | ||
|
||
const wiSunConnector = createWiSunConnector("BP35C2", "devicePath"); | ||
|
||
expect(MockBP35Connector).toHaveBeenCalledWith("devicePath", 0); | ||
expect(wiSunConnector).toBeInstanceOf(BP35Connector); | ||
}); | ||
|
||
test("side指定なしモデルのインスタンスを取得できる", () => { | ||
const MockBP35Connector = jest.mocked(BP35Connector, { shallow: true }); | ||
|
||
const wiSunConnector = createWiSunConnector("BP35A1", "devicePath"); | ||
|
||
expect(MockBP35Connector).toHaveBeenCalledWith("devicePath"); | ||
expect(wiSunConnector).toBeInstanceOf(BP35Connector); | ||
}); | ||
|
||
test("不正なモデルの場合例外をすろーする", () => { | ||
jest.mocked(BP35Connector, { shallow: true }); | ||
|
||
const actual = () => | ||
createWiSunConnector("unknown" as WiSunConnectorModel, "devicePath"); | ||
|
||
expect(actual).toThrow(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import { Entity } from "@/entity"; | ||
import { buildDevice, buildEntity, buildOrigin } from "@/payload/builder"; | ||
import { TopicType } from "@/payload/topic"; | ||
|
||
describe("buildEntity", () => { | ||
test("必要な属性が揃っている", () => { | ||
const mockEntity = { | ||
id: "entity1", | ||
name: "Test Entity", | ||
deviceClass: "energy", | ||
stateClass: "total_increasing", | ||
unit: "kWh", | ||
nativeValue: "float", | ||
unitPrecision: 3, | ||
} as Entity; | ||
|
||
const entity = buildEntity("deviceId1", mockEntity); | ||
|
||
expect(entity).toHaveProperty("unique_id", "wisun2mqtt_deviceId1_entity1"); | ||
expect(entity).toHaveProperty("name", "Test Entity"); | ||
expect(entity).toHaveProperty( | ||
"state_topic", | ||
`wisun2mqtt/deviceId1/entity1/${TopicType.STATE}`, | ||
); | ||
expect(entity).toHaveProperty( | ||
"availability_topic", | ||
`wisun2mqtt/deviceId1/entity1/${TopicType.AVAILABILITY}`, | ||
); | ||
expect(entity).toHaveProperty("device_class", "energy"); | ||
expect(entity).toHaveProperty("state_class", "total_increasing"); | ||
expect(entity).toHaveProperty("unit_of_measurement", "kWh"); | ||
expect(entity).toHaveProperty("native_value", "float"); | ||
expect(entity).toHaveProperty("suggested_display_precision", 3); | ||
expect(entity).toHaveProperty("qos"); | ||
}); | ||
}); | ||
|
||
describe("buildDevice", () => { | ||
test("必要な属性が揃っている", () => { | ||
const device = buildDevice("deviceId1", "manufacturer"); | ||
expect(device).toHaveProperty("device.identifiers"); | ||
expect(device).toHaveProperty("device.name"); | ||
expect(device).toHaveProperty("device.manufacturer"); | ||
}); | ||
}); | ||
|
||
describe("buildOrigin", () => { | ||
test("必要な属性が揃っている", async () => { | ||
const origin = await buildOrigin(); | ||
expect(origin).toHaveProperty("origin.name"); | ||
expect(origin).toHaveProperty("origin.sw_version"); | ||
expect(origin).toHaveProperty("origin.support_url"); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters