-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(tests): add GameMessagePayload copy test
- Loading branch information
Showing
1 changed file
with
56 additions
and
0 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,56 @@ | ||
import { describe, it, expect } from "vitest"; | ||
import { GameMessagePayload } from "../src/GameMessagePayload.js"; | ||
|
||
describe("GameMessagePayload", () => { | ||
it("should create a copy of the payload", () => { | ||
const originalPayload = new GameMessagePayload(); | ||
originalPayload.deserialize(Buffer.from("test data")); | ||
|
||
const copiedPayload = GameMessagePayload.copy(originalPayload); | ||
|
||
expect(copiedPayload).not.toBe(originalPayload); | ||
expect(copiedPayload.serialize()).toEqual(originalPayload.serialize()); | ||
}); | ||
|
||
it("should return the correct byte size", () => { | ||
const payload = new GameMessagePayload(); | ||
payload.deserialize(Buffer.from("test data")); | ||
|
||
expect(payload.getByteSize()).toBe(9); | ||
}); | ||
|
||
it("should serialize the payload correctly", () => { | ||
const payload = new GameMessagePayload(); | ||
const buffer = Buffer.from("test data"); | ||
payload.deserialize(buffer); | ||
|
||
expect(payload.serialize()).toEqual(buffer); | ||
}); | ||
|
||
it("should deserialize the payload correctly", () => { | ||
const payload = new GameMessagePayload(); | ||
const buffer = Buffer.from("test data"); | ||
payload.deserialize(buffer); | ||
|
||
expect(payload.serialize()).toEqual(buffer); | ||
}); | ||
|
||
it("should correctly indicate if the payload is encrypted", () => { | ||
const payload = new GameMessagePayload(); | ||
|
||
expect(payload.isPayloadEncrypted()).toBe(false); | ||
|
||
payload.setPayloadEncryption(true); | ||
expect(payload.isPayloadEncrypted()).toBe(true); | ||
}); | ||
|
||
it("should set the payload encryption correctly", () => { | ||
const payload = new GameMessagePayload(); | ||
|
||
payload.setPayloadEncryption(true); | ||
expect(payload.isPayloadEncrypted()).toBe(true); | ||
|
||
payload.setPayloadEncryption(false); | ||
expect(payload.isPayloadEncrypted()).toBe(false); | ||
}); | ||
}); |