Skip to content
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

Ensure that Realm enums are accessible #5484

Merged
merged 6 commits into from
Feb 24, 2023
Merged

Conversation

JacobOscarGunnarsson
Copy link
Contributor

Small tests to make sure that the issue in #3365 is resolved

describe("ConnectionState", function () {
it("is accessible", function () {
expect(typeof ConnectionState === "object");
expect(typeof ConnectionState.Disconnected === "string");
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Could be redundant to check all enum values, feel free to add thoughts about this.

Copy link
Contributor

@elle-j elle-j Feb 23, 2023

Choose a reason for hiding this comment

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

I'd vote for keeping them (i.e. testing all values). Even though the issue mentioned asserting that the value is a string, we'd get more accurate tests if we compare it to the actual string value (e.g. "disconnected").

On a smaller note, perhaps we want to structure them more toward "natural language"? E.g.:

// This will pass for e.g. arrays as well.
expect(typeof ConnectionState).to.equal("object");

// This will not pass for arrays.
expect(ConnectionState).to.be.an("object");

expect(ConnectionState.Disconnected).to.equal("disconnected");
expect(ConnectionState.Connecting).to.equal("connecting");
// Fixed typo from `Connecting` to `Connected`
expect(ConnectionState.Connected).to.equal("connected");

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yeah went through this a bit too fast 🤦 using mocha as extensively as possible is what we've already done in test-migration-master so should aim for that! Thanks for pointing it out

Copy link
Contributor

Choose a reason for hiding this comment

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

Np 👍 (perhaps to.deep.equal() could test all those cases at once as well)

Copy link
Member

@kraenhansen kraenhansen Feb 24, 2023

Choose a reason for hiding this comment

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

Could be redundant to check all enum values.

I'm probably feeling this a bit. If these tests fail it'll either be because we (hopefully consciously) changed the enums or the TS compiler is broken (in which case this will be the least of our worries). These tests are in risk of becoming outdated if we add new values to the enum.

The main reason we had these issues on master was because we declared types separately from implementation (in JS), so I probably don't feel the need for this to be a part of our test suite. But then again - they are written now, so they don't hurt too much to keep 😅

(and sorry for being late to the party here).

Copy link
Contributor

@elle-j elle-j left a comment

Choose a reason for hiding this comment

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

Nice :D Got some suggestions 👍

describe("ConnectionState", function () {
it("is accessible", function () {
expect(typeof ConnectionState === "object");
expect(typeof ConnectionState.Disconnected === "string");
Copy link
Contributor

@elle-j elle-j Feb 23, 2023

Choose a reason for hiding this comment

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

I'd vote for keeping them (i.e. testing all values). Even though the issue mentioned asserting that the value is a string, we'd get more accurate tests if we compare it to the actual string value (e.g. "disconnected").

On a smaller note, perhaps we want to structure them more toward "natural language"? E.g.:

// This will pass for e.g. arrays as well.
expect(typeof ConnectionState).to.equal("object");

// This will not pass for arrays.
expect(ConnectionState).to.be.an("object");

expect(ConnectionState.Disconnected).to.equal("disconnected");
expect(ConnectionState.Connecting).to.equal("connecting");
// Fixed typo from `Connecting` to `Connected`
expect(ConnectionState.Connected).to.equal("connected");

integration-tests/tests/src/tests/enums.ts Outdated Show resolved Hide resolved
Copy link
Contributor

@elle-j elle-j left a comment

Choose a reason for hiding this comment

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

😎

Copy link
Contributor

@gagik gagik left a comment

Choose a reason for hiding this comment

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

Nice, just a minor suggestion

expect(typeof NumericLogLevel.Trace === "number");
expect(typeof NumericLogLevel.Warn === "number");
expect(NumericLogLevel).to.be.an("object");
expect(NumericLogLevel.All).equals(0);
Copy link
Contributor

Choose a reason for hiding this comment

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

alternatively you could possibly (but I am not sure if this will work?) do a deep equal with an object i.e.

expect(NumericLogLevel).deep.equals({
          All: 0,
          Trace: 1
           ...
});

This might be better as well in case in the future we add a new value to the enum, as it would cause the test to fail, which it wouldn't with the current approach. Same for other enums. Again, not sure if this will work how I think it'll work.

Copy link
Contributor

Choose a reason for hiding this comment

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

Just realized @elle-j had the same idea

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'll give it a shot, was a bit concerned that the syntax would make it less readable but the point with adding new values is very valid!

@JacobOscarGunnarsson
Copy link
Contributor Author

I added the deep.equals, I'm a but torn on how it looks with the NumericLogLevel, but it might be worth it

Comment on lines 69 to 70
expect(NumericLogLevel).to.be.an("object");
expect(NumericLogLevel).to.deep.equals({
Copy link
Contributor

Choose a reason for hiding this comment

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

This first line shouldn't be needed when you're doing deep equals to an object. Btw, does it still work with having the sat the end of equal? (I'd vote for where you're using to.deep.equal()) :)

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah, most of these "to" "be" "equal/equals" are just meaningless syntactic sugar that does not change its behavior. So it could be expect(NumericLogLevel).deep.equals or expect(NumericLogLevel).to.deep.equal. I like both, I have generally been using the former for less use of this chaining but the latter does read nicer.

});
describe("NumericLogLevel", function () {
it("is accessible", function () {
expect(NumericLogLevel).to.deep.equal({
Copy link
Contributor

@gagik gagik Feb 23, 2023

Choose a reason for hiding this comment

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

Just checked and we do use .deep.equals 161 trimes and .to.deep.equal 9 times... with that in mind I am leaning towards being consistent... sorry for leading you wrong way but I don't feel strongly about this if others don't

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I like consistency so I appreciate that you lifted this :D

@JacobOscarGunnarsson JacobOscarGunnarsson merged commit f14917b into bindgen Feb 24, 2023
@JacobOscarGunnarsson JacobOscarGunnarsson deleted the jg/realm_enums branch February 24, 2023 09:13
papafe added a commit that referenced this pull request Feb 24, 2023
* bindgen:
  Implement getAllSyncSessions (#5492)
  Ensure that Realm enums are accessible (#5484)
  Apply suggestions from code review [skip ci]
  Small corrections [skip ci]
  Added changelog and final corrections
  Stub
  add test to validate that foreach throws on a dictionary (#5467)
  Using `RealmInsertionModel` on `Results#update`
  Updated "react-native" dev dep to 0.71.0
  Bumped lower bound on our RN peer dependency
  [bindgen] SDK packaging (#5466)
  Adding "prebuild" and configuring it (#5447)
  add synthetic private brand fields to TS wrappers for C++ classes, and fix found bug
  import bindings directly rather than through internal
  Stub work
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 15, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants