forked from roundware/roundware-web-framework
-
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.
tests so far that i didn't pushed earlier
- Loading branch information
1 parent
390453e
commit 65e5c13
Showing
19 changed files
with
666 additions
and
36 deletions.
There are no files selected for viewing
Binary file not shown.
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
import { IAudioContext, IStereoPannerNode } from "standardized-audio-context"; | ||
import { AudioPanner } from "../../src/audioPanner"; | ||
import { random } from "../../src/utils"; | ||
|
||
jest.mock("../../src/utils"); | ||
|
||
const mockRandom = random as jest.MockedFunction<typeof random>; | ||
|
||
describe("AudioPanner", () => { | ||
afterEach(() => { | ||
jest.clearAllMocks(); | ||
}); | ||
|
||
test("should instantiate AudioPanner", () => { | ||
const audioContext = {} as IAudioContext; | ||
const panNode = {} as IStereoPannerNode<IAudioContext>; | ||
|
||
const audioPanner = new AudioPanner(0, 1, 2, 3, panNode, audioContext); | ||
|
||
expect(audioPanner).toBeInstanceOf(AudioPanner); | ||
}); | ||
|
||
test("should update parameters", () => { | ||
const audioContext = {} as IAudioContext; | ||
const panNode = {} as IStereoPannerNode<IAudioContext>; | ||
const audioPanner = new AudioPanner(0, 1, 2, 3, panNode, audioContext); | ||
|
||
audioPanner.updateParams(); | ||
|
||
expect(mockRandom).toHaveBeenCalledTimes(3); // Called for initial, final, and duration | ||
}); | ||
|
||
test("should start panning", () => { | ||
const audioContext = { | ||
currentTime: 0, | ||
} as IAudioContext; | ||
const panNode = { | ||
pan: { | ||
value: 0, | ||
linearRampToValueAtTime: jest.fn(), | ||
}, | ||
} as unknown as IStereoPannerNode<IAudioContext>; | ||
|
||
const audioPanner = new AudioPanner(0, 1, 2, 3, panNode, audioContext); | ||
|
||
audioPanner.start(); | ||
|
||
expect(panNode.pan.linearRampToValueAtTime).toHaveBeenCalledWith( | ||
expect.any(Number), | ||
expect.any(Number) | ||
); | ||
|
||
// Ensure the timer function is called | ||
jest.runOnlyPendingTimers(); | ||
expect(mockRandom).toHaveBeenCalledTimes(3); // Called for initial, final, and duration | ||
}); | ||
|
||
test("should clear timeout", () => { | ||
const audioContext = {} as IAudioContext; | ||
const panNode = {} as IStereoPannerNode<IAudioContext>; | ||
|
||
const audioPanner = new AudioPanner(0, 1, 2, 3, panNode, audioContext); | ||
|
||
audioPanner.start(); | ||
audioPanner.clear(); | ||
|
||
expect(clearTimeout).toHaveBeenCalled(); | ||
}); | ||
}); |
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,118 @@ | ||
// Import necessary dependencies and the RoundwareEvents class | ||
|
||
import { ApiClient } from "../../src/api-client"; | ||
import { RoundwareEvents } from "../../src/events"; | ||
import { EventType, EventPayload } from "../../src/types/events"; | ||
|
||
// Mock the ApiClient class | ||
jest.mock("../../src/api-client"); | ||
|
||
describe("RoundwareEvents", () => { | ||
let roundwareEvents: RoundwareEvents; | ||
let mockApiClient: jest.Mocked<ApiClient>; | ||
|
||
beforeEach(() => { | ||
mockApiClient = new ApiClient("") as jest.Mocked<ApiClient>; | ||
roundwareEvents = new RoundwareEvents(123, mockApiClient); | ||
}); | ||
|
||
afterEach(() => { | ||
jest.clearAllMocks(); | ||
}); | ||
|
||
describe("logAssetStart", () => { | ||
it("should log asset start and update _startedAssets", async () => { | ||
const assetId = 1; | ||
const startTime = new Date(); | ||
|
||
// Mock the post method of ApiClient | ||
mockApiClient.post.mockResolvedValue({ id: 456 }); | ||
|
||
await roundwareEvents.logAssetStart(assetId, startTime); | ||
|
||
expect(mockApiClient.post).toHaveBeenCalledWith("/listenevents/", { | ||
starttime: startTime, | ||
session: 123, | ||
asset: assetId, | ||
}); | ||
|
||
expect(roundwareEvents["_startedAssets"]).toHaveProperty( | ||
assetId.toString(), | ||
expect.objectContaining({ startTime, id: 456 }) | ||
); | ||
}); | ||
|
||
it("should log asset start with default startTime if not provided", async () => { | ||
const assetId = 1; | ||
|
||
// Mock the post method of ApiClient | ||
mockApiClient.post.mockResolvedValue({ id: 456 }); | ||
|
||
await roundwareEvents.logAssetStart(assetId); | ||
|
||
expect(mockApiClient.post).toHaveBeenCalledWith("/listenevents/", { | ||
starttime: expect.any(Date), | ||
session: 123, | ||
asset: assetId, | ||
}); | ||
|
||
expect(roundwareEvents["_startedAssets"]).toHaveProperty( | ||
assetId.toString(), | ||
expect.objectContaining({ startTime: expect.any(Date), id: 456 }) | ||
); | ||
}); | ||
}); | ||
|
||
describe("logAssetEnd", () => { | ||
it("should log asset end if assetId exists in _startedAssets", async () => { | ||
const assetId = 1; | ||
const startTime = new Date(); | ||
roundwareEvents["_startedAssets"][assetId] = { startTime, id: 789 }; | ||
|
||
// Mock the patch method of ApiClient | ||
mockApiClient.patch.mockResolvedValue({}); | ||
|
||
await roundwareEvents.logAssetEnd(assetId); | ||
|
||
expect(mockApiClient.patch).toHaveBeenCalledWith( | ||
"/listenevents/789", | ||
expect.objectContaining({ | ||
duration_in_seconds: expect.any(Number), | ||
}) | ||
); | ||
}); | ||
|
||
it("should not log asset end if assetId does not exist in _startedAssets", async () => { | ||
const assetId = 1; | ||
|
||
// Mock the patch method of ApiClient | ||
mockApiClient.patch.mockResolvedValue({}); | ||
|
||
await roundwareEvents.logAssetEnd(assetId); | ||
|
||
expect(mockApiClient.patch).not.toHaveBeenCalled(); | ||
}); | ||
}); | ||
|
||
describe("logEvent", () => { | ||
it("should log an event using the post method of ApiClient", async () => { | ||
const eventType: EventType = "start_session"; | ||
const payload: EventPayload = { | ||
latitude: 40.7128, | ||
longitude: -74.006, | ||
}; | ||
|
||
// Mock the post method of ApiClient | ||
mockApiClient.post.mockResolvedValue(payload); | ||
|
||
await roundwareEvents.logEvent(eventType, payload); | ||
|
||
expect(mockApiClient.post).toHaveBeenCalledWith("/events/", { | ||
session_id: 123, | ||
event_type: eventType, | ||
client_time: expect.any(String), | ||
...payload, | ||
}); | ||
}); | ||
}); | ||
}); |
Empty file.
Empty file.
Oops, something went wrong.