-
Notifications
You must be signed in to change notification settings - Fork 2
fix: publishReply has incorrect Event in reply #141
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
a453e06
fix: publishReply has incorrect Event in reply
gismya 4f2110b
Corrected source preparation
gismya 47ba004
Apply suggestions from code review
gismya b1c1bac
PR suggestions
gismya 8879010
feat(TS): Changed tests to TypeScript and updated typings (#136)
ffMathy e240e37
feat(TS): Changed tests to TypeScript and updated typings (#136)
ffMathy e1cdf11
Merge branch 'main' into publish-reply-incorrect-event-shape
gismya 8306698
Empty-merge
gismya b19f5c2
Event dropped out in merges
gismya File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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,98 @@ | ||
// :copyright: Copyright (c) 2023 ftrack | ||
gismya marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
import { Event } from "../source/event"; | ||
import { describe, expect, it } from "vitest"; | ||
|
||
describe("Event class", () => { | ||
it("should initialize with correct topic and data", () => { | ||
const event = new Event("testTopic", { key: "value" }); | ||
const data = event.getData(); | ||
expect(data.topic).toBe("testTopic"); | ||
expect(data.data).toEqual({ key: "value" }); | ||
}); | ||
|
||
it("should have default properties", () => { | ||
const event = new Event("testTopic", { key: "value" }); | ||
const data = event.getData(); | ||
expect(data.target).toBe(""); | ||
expect(data.inReplyToEvent).toBeNull(); | ||
}); | ||
|
||
it("should set properties from options", () => { | ||
const event = new Event( | ||
"testTopic", | ||
{ key: "value" }, | ||
{ target: "sampleTarget", customOption: "customValue" } | ||
); | ||
const data = event.getData(); | ||
expect(data.target).toBe("sampleTarget"); | ||
expect(data.customOption).toBe("customValue"); | ||
}); | ||
|
||
it("should generate unique UUID", () => { | ||
const event1 = new Event("testTopic", { key: "value" }); | ||
const event2 = new Event("testTopic", { key: "value" }); | ||
const data1 = event1.getData(); | ||
const data2 = event2.getData(); | ||
const uuidRegexExp = | ||
/^[0-9a-fA-F]{8}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{12}$/gi; | ||
expect(data1.id).not.toBe(data2.id); | ||
expect(uuidRegexExp.test(data1.id)).toBe(true); | ||
}); | ||
|
||
it("should add source to event data", () => { | ||
const event = new Event("testTopic", { key: "value" }); | ||
const source = { | ||
id: "testId", | ||
applicationId: "testApplicationId", | ||
user: { | ||
username: "testUser", | ||
}, | ||
}; | ||
event.addSource(source); | ||
const data = event.getData(); | ||
expect(data.source).toBe(source); | ||
}); | ||
describe("prepareSource Method", () => { | ||
it("should prepare and add source to event data", () => { | ||
const event = new Event("testTopic", { key: "value" }); | ||
event.prepareSource({ newKey: "newValue" }); | ||
const data = event.getData(); | ||
expect(data.source).toEqual({ newKey: "newValue" }); | ||
}); | ||
|
||
it("should not override existing source when preparing a new source", () => { | ||
const event = new Event( | ||
"testTopic", | ||
{ key: "value" }, | ||
{ source: { oldKey: "oldValue" } } | ||
); | ||
event.prepareSource({ oldKey: "newValue", newKey: "newValue" }); | ||
const data = event.getData(); | ||
expect(data.source).toEqual({ | ||
oldKey: "oldValue", | ||
newKey: "newValue", | ||
}); | ||
}); | ||
it("should handle source undefined", () => { | ||
const event = new Event( | ||
"testTopic", | ||
{ key: "value" }, | ||
{ source: undefined } | ||
); | ||
event.prepareSource({ newKey: "newValue" }); | ||
const data = event.getData(); | ||
expect(data.source).toEqual({ | ||
newKey: "newValue", | ||
}); | ||
}); | ||
it("Prepare should handle source null", () => { | ||
const event = new Event("testTopic", { key: "value" }, { source: null }); | ||
event.prepareSource({ newKey: "newValue" }); | ||
const data = event.getData(); | ||
expect(data.source).toEqual({ | ||
newKey: "newValue", | ||
}); | ||
}); | ||
}); | ||
}); |
This file contains hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.