Skip to content

Refactor EventModLookup and add tests#161

Merged
JonoPrest merged 7 commits into
mainfrom
jp/refactor-event-lookup
Sep 2, 2024
Merged

Refactor EventModLookup and add tests#161
JonoPrest merged 7 commits into
mainfrom
jp/refactor-event-lookup

Conversation

@JonoPrest

@JonoPrest JonoPrest commented Aug 30, 2024

Copy link
Copy Markdown
Collaborator
  • moves all Js.Dict.get to optimized util
  • Adds a field for quick lookup of wildcard events
  • Adds test coverage of all the core functions in the module
Screenshot 2024-08-30 at 14 39 20

@JonoPrest JonoPrest requested a review from DZakh August 30, 2024 12:41
@JonoPrest JonoPrest force-pushed the jp/refactor-event-lookup branch 2 times, most recently from bcd5593 to 16ae59a Compare August 30, 2024 12:50

@module("assert")
external throws: (unit => 'a, ~error: Js.Exn.t, ~message: string=?) => unit = "throws"
external throws: (unit => 'a, ~error: Js.Exn.t=?, ~message: string=?) => unit = "throws"

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is correct? I didn't actually want to pass in the expected error.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I think it's correct to have it optional. But the field is usually used to test error messages, which I think we should also do. But I'm not sure that the Js.Exn.t is correct here, for example in Ava.js I usually use you can pass a simple object with error assertions.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@DZakh DZakh left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks very good. And having tests for error messages will make it even better :)

Event.handlerRegister->Types.HandlerTypes.Register.getEventOptions->(v => v.Types.HandlerTypes.wildcard)
Event.handlerRegister
->Types.HandlerTypes.Register.getEventOptions
->(v => v.Types.HandlerTypes.wildcard)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the first time I see the syntax 😁

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Haha, I don't really have too strong an opinion but thought it flows better than using round brackets around the whole statement and accessing .wildcard at the end. I might use it again.


@module("assert")
external throws: (unit => 'a, ~error: Js.Exn.t, ~message: string=?) => unit = "throws"
external throws: (unit => 'a, ~error: Js.Exn.t=?, ~message: string=?) => unit = "throws"

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I think it's correct to have it optional. But the field is usually used to test error messages, which I think we should also do. But I'm not sure that the Js.Exn.t is correct here, for example in Ava.js I usually use you can pass a simple object with error assertions.


@module("assert")
external throws: (unit => 'a, ~error: Js.Exn.t, ~message: string=?) => unit = "throws"
external throws: (unit => 'a, ~error: Js.Exn.t=?, ~message: string=?) => unit = "throws"

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment thread codegenerator/cli/templates/static/codegen/src/bindings/RescriptMocha.res Outdated
Comment on lines +229 to +233
Assert.throws(
() => {
Error({eventMod, errorKind})->EventModLookup.unwrapAddEventResponse(~chain=mockChain)
},
)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Assert.throws(
() => {
Error({eventMod, errorKind})->EventModLookup.unwrapAddEventResponse(~chain=mockChain)
},
)
Assert.throws(
() => {
Error({eventMod, errorKind})->EventModLookup.unwrapAddEventResponse(~chain=mockChain)
},
~error={
"message": "I don't know what, but it should be tested"
}
)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, it'll require to remove forEach

@JonoPrest JonoPrest force-pushed the jp/refactor-event-lookup branch from 3637044 to dc60a23 Compare September 2, 2024 08:26
@JonoPrest JonoPrest enabled auto-merge (squash) September 2, 2024 08:27
@JonoPrest JonoPrest force-pushed the jp/refactor-event-lookup branch from dc60a23 to 222a817 Compare September 2, 2024 08:34
@JonoPrest JonoPrest merged commit dbaa1f5 into main Sep 2, 2024
@JonoPrest JonoPrest deleted the jp/refactor-event-lookup branch September 2, 2024 08:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants