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
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions integration-tests/tests/src/tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ import "./tests/objects";
import "./tests/queries";
import "./tests/realm-constructor";
import "./tests/schema";
import "./tests/enums";
import "./tests/serialization";
import "./tests/set";
import "./tests/list";
Expand Down
73 changes: 73 additions & 0 deletions integration-tests/tests/src/tests/enums.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
////////////////////////////////////////////////////////////////////////////
//
// Copyright 2023 Realm Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
////////////////////////////////////////////////////////////////////////////

import { expect } from "chai";
import {
ConnectionState,
NumericLogLevel,
OpenRealmBehaviorType,
OpenRealmTimeOutBehavior,
SessionStopPolicy,
} from "realm";

describe("Enums", function () {
describe("ConnectionState", function () {
it("is accessible", function () {
expect(ConnectionState).to.be.an("object");
expect(ConnectionState.Disconnected).equals("disconnected");
expect(ConnectionState.Connecting).equals("connecting");
expect(ConnectionState.Connected).equals("connected");
});
});
describe("SessionStopPolicy", function () {
it("is accessible", function () {
expect(SessionStopPolicy).to.be.an("object");
expect(SessionStopPolicy.AfterUpload).equals("after-upload");
expect(SessionStopPolicy.Immediately).equals("immediately");
expect(SessionStopPolicy.Never).equals("never");
});
});
describe("OpenRealmBehaviourType", function () {
it("is accessible", function () {
expect(OpenRealmBehaviorType).to.be.an("object");
expect(OpenRealmBehaviorType.DownloadBeforeOpen).equals("downloadBeforeOpen");
expect(OpenRealmBehaviorType.OpenImmediately).equals("openImmediately");
});
});
describe("OpenRealmTimeOutBehaviour", function () {
it("is accessible", function () {
expect(OpenRealmTimeOutBehavior).to.be.an("object");
expect(OpenRealmTimeOutBehavior.OpenLocalRealm).equals("openLocalRealm");
expect(OpenRealmTimeOutBehavior.ThrowException).equals("throwException");
});
});
describe("NumericLogLevel", function () {
it("is accessible", function () {
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!

expect(NumericLogLevel.Trace).equals(1);
expect(NumericLogLevel.Debug).equals(2);
expect(NumericLogLevel.Detail).equals(3);
expect(NumericLogLevel.Info).equals(4);
expect(NumericLogLevel.Warn).equals(5);
expect(NumericLogLevel.Error).equals(6);
expect(NumericLogLevel.Fatal).equals(7);
expect(NumericLogLevel.Off).equals(8);
});
});
});