* CEC-2056 safari map (#186) * CEC-2056 Fix Safari map popup * Snapshot serializer for Private styles * Combine serializers * CEC-2207 Add is-online filter for vehicles list (#187) * Add OptionsDropdown component * Add is-online filter * CEC-2237 Track sign in and keys (#188) * Update stage (#189) * CEC-2056 safari map (#186) * CEC-2056 Fix Safari map popup * Snapshot serializer for Private styles * Combine serializers * CEC-2207 Add is-online filter for vehicles list (#187) * Add OptionsDropdown component * Add is-online filter * CEC-2237 Track sign in and keys (#188) Co-authored-by: arpanetus <arpanetus@protonmail.com> * CEC-2281 Update certificate form (#190) * CEC-2281 Fix cert name * CEC-2360 Fix filename display and add manifest type (#191) * CEC-2360 Fix filename display and add manifest type * const * Push to Stage (#200) * CEC-2144, CEC-2338 Add deploy by fleets and fix fleets table (#192) * Add fix for fleets search * Decompose fleets table * Add deploy by fleets * Add snapshots * CEC-2385 Only show software updates (#193) * CEC-2385 Only show software updates * Update browser list * update threshold * Clean up * CEC-2291 Remote Commands (#194) * CEC-2378 Add fix for fleet vehicles' search * CEC-1235 Fix fleet name update (#196) Co-authored-by: arpanetus <arpanetus@protonmail.com> Co-authored-by: arpanetus <arpanetus@protonmail.com>
150 lines
4.1 KiB
JavaScript
150 lines
4.1 KiB
JavaScript
import {emptyCommands, hmol, hmolCommands, onOff, onOffCommands, onOffTemp, precond, sanitize,} from "./sanitize";
|
|
|
|
const randomValues = [null, undefined, "someString", 33]
|
|
|
|
describe("Sanitize test", () => {
|
|
it("empty commands", () => {
|
|
for (const command of emptyCommands) {
|
|
const cmd = sanitize({command})
|
|
expect(cmd.command).toEqual(command)
|
|
expect("data" in cmd).toEqual(false);
|
|
expect("start" in cmd).toEqual(false);
|
|
expect("end" in cmd).toEqual(false);
|
|
}
|
|
})
|
|
|
|
it("on-off commands with proper values", () => {
|
|
for (const command of onOffCommands) {
|
|
for (const data of [false, true]) {
|
|
const cmd = sanitize({command, data})
|
|
|
|
expect(cmd.data).toEqual(onOff[data])
|
|
expect(cmd.command).toEqual(command)
|
|
expect("start" in cmd).toEqual(false);
|
|
expect("end" in cmd).toEqual(false);
|
|
}
|
|
}
|
|
})
|
|
|
|
it("on-off commands with dirty values", () => {
|
|
for (const command of onOffCommands) {
|
|
const cmd = {command}
|
|
for (const rVal of randomValues) {
|
|
if (rVal !== undefined) {
|
|
cmd.data = rVal
|
|
}
|
|
const res = sanitize(cmd)
|
|
|
|
expect(res.data).toEqual("off")
|
|
expect(res.command).toEqual(command)
|
|
expect("start" in res).toEqual(false);
|
|
expect("end" in res).toEqual(false);
|
|
}
|
|
}
|
|
})
|
|
|
|
it("high-mid-low-off with proper values", () => {
|
|
for (const command of hmolCommands) {
|
|
for (const data of [0,1,2,3]) {
|
|
const cmd = sanitize({command, data})
|
|
|
|
expect(cmd.data).toEqual(hmol[data])
|
|
expect(cmd.command).toEqual(command)
|
|
expect("start" in cmd).toEqual(false);
|
|
expect("end" in cmd).toEqual(false);
|
|
}
|
|
}
|
|
})
|
|
|
|
it("precondition with proper values", () => {
|
|
for (const data of [0,1,2,3]) {
|
|
const cmd = sanitize({command:"precondition", data})
|
|
|
|
expect(cmd.data).toEqual(precond[data])
|
|
expect(cmd.command).toEqual("precondition")
|
|
expect("start" in cmd).toEqual(false);
|
|
expect("end" in cmd).toEqual(false);
|
|
}
|
|
})
|
|
|
|
it("precondition with wrong values", () => {
|
|
const cmd = {command:"precondition"}
|
|
for (const rVal of randomValues) {
|
|
if (rVal !== undefined) {
|
|
cmd.data = rVal
|
|
}
|
|
const res = sanitize(cmd)
|
|
|
|
expect(res.data).toEqual("battery")
|
|
expect(res.command).toEqual("precondition")
|
|
expect("start" in res).toEqual(false);
|
|
expect("end" in res).toEqual(false);
|
|
}
|
|
})
|
|
|
|
|
|
|
|
it("high-mid-low-off with wrong values", () => {
|
|
for (const command of hmolCommands) {
|
|
const cmd = {command}
|
|
for (const rVal of randomValues) {
|
|
if (rVal !== undefined) {
|
|
cmd.data = rVal
|
|
}
|
|
const res = sanitize(cmd)
|
|
|
|
expect(res.data).toEqual("off")
|
|
expect(res.command).toEqual(command)
|
|
expect("start" in res).toEqual(false);
|
|
expect("end" in res).toEqual(false);
|
|
}
|
|
}
|
|
})
|
|
|
|
it("open trunk", () => {
|
|
const cmd = {command: "trunk_open"}
|
|
for (let i = 1; i <= 5; i++) {
|
|
cmd.data = i
|
|
|
|
const res = sanitize(cmd)
|
|
|
|
expect(res.data).toEqual(i.toString())
|
|
expect(res.command).toEqual("trunk_open")
|
|
expect("start" in res).toEqual(false);
|
|
expect("end" in res).toEqual(false);
|
|
}
|
|
})
|
|
|
|
it("open trunk with wrong values", () => {
|
|
const cmd = {command: "trunk_open"}
|
|
for (const rVal of randomValues) {
|
|
if (rVal !== undefined) {
|
|
cmd.data = rVal
|
|
}
|
|
const res = sanitize(cmd)
|
|
|
|
expect(res.data).toEqual("1")
|
|
expect(res.command).toEqual("trunk_open")
|
|
expect("start" in res).toEqual(false);
|
|
expect("end" in res).toEqual(false);
|
|
}
|
|
})
|
|
|
|
|
|
it("cabin temp with period with proper values", () => {
|
|
for (let i = 0; i <= 27; i++) {
|
|
const res = sanitize({
|
|
command: "temp_cabin",
|
|
data: i,
|
|
start: new Date(),
|
|
end: new Date(),
|
|
})
|
|
|
|
|
|
expect(res.command).toEqual("temp_cabin")
|
|
expect(res.data).toEqual(onOffTemp[i])
|
|
expect(typeof res.start).toEqual("object")
|
|
expect(typeof res.end).toEqual("object")
|
|
}
|
|
})
|
|
}) |