-
Notifications
You must be signed in to change notification settings - Fork 558
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
151 additions
and
14 deletions.
There are no files selected for viewing
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
50 changes: 50 additions & 0 deletions
50
integration-tests/tests/src/tests/experimental/base-url.ts
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,50 @@ | ||
//////////////////////////////////////////////////////////////////////////// | ||
// | ||
// Copyright 2024 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 "realm/experimental/base-url"; | ||
|
||
import { baseUrl as originalBaseUrl, importAppBefore } from "../../hooks"; | ||
import { buildAppConfig } from "../../utils/build-app-config"; | ||
|
||
describe.skipIf(environment.missingServer, "Base URL", () => { | ||
importAppBefore(buildAppConfig("with-anon").anonAuth()); | ||
|
||
it("returns the base URL used", function (this: AppContext) { | ||
expect(this.app.baseUrl).equals(originalBaseUrl); | ||
}); | ||
|
||
it.skip("updates the URL", async function (this: AppContext) { | ||
// TODO | ||
}); | ||
|
||
it("throws when assigning via setter", function (this: AppContext) { | ||
// @ts-expect-error Assigning to read-only property. | ||
expect(() => (this.app.baseUrl = "new URL")).to.throw("Cannot assign the base URL, please use 'updateBaseUrl()'"); | ||
|
||
expect(this.app.baseUrl).equals(originalBaseUrl); | ||
}); | ||
|
||
it("rejects when updating to invalid URL", async function (this: AppContext) { | ||
await expect(this.app.updateBaseUrl("https://invalid")).to.be.rejectedWith( | ||
"request to https://invalid/api/client/", | ||
); | ||
|
||
expect(this.app.baseUrl).equals(originalBaseUrl); | ||
}); | ||
}); |
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 |
---|---|---|
|
@@ -4,4 +4,4 @@ | |
{ "path": "./tsconfig.common.json" }, | ||
{ "path": "./tsconfig.node.json" } | ||
] | ||
} | ||
} |
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,29 @@ | ||
//////////////////////////////////////////////////////////////////////////// | ||
// | ||
// Copyright 2024 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. | ||
// | ||
//////////////////////////////////////////////////////////////////////////// | ||
|
||
// Our use of `exports` in `packages/realm/package.json` is not enabled by | ||
// default when using Metro and RN. In these cases, modules imported from | ||
// "realm/experimental" will search for the file in the same path, rather | ||
// than what is pointed to under `exports`. Thus, we use this .js file to | ||
// in turn import the necessary module. | ||
|
||
// (Enabling `unstable_enablePackageExports` in the metro config unexpectedly | ||
// does not work.) | ||
|
||
/* eslint-env commonjs */ | ||
module.exports = require("../dist/experimental/base-url"); |
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,54 @@ | ||
//////////////////////////////////////////////////////////////////////////// | ||
// | ||
// Copyright 2024 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 { App } from "../app-services/App"; | ||
|
||
declare module "../app-services/App" { | ||
interface App { | ||
/** | ||
* Get the current base URL used for sending requests to Atlas App Services. | ||
* If an {@link App.updateBaseUrl | updateBaseUrl } operation is currently in | ||
* progress, this value will not be updated with the new value until that | ||
* operation has completed. | ||
* @experimental This feature is experimental and may be changed or removed. | ||
*/ | ||
get baseUrl(): string; | ||
|
||
/** | ||
* Update the base URL used for sending requests to Atlas App Services. | ||
* If this operation fails, the app will continue to use the original base URL. | ||
* If another {@link App} operation is started while this function is in progress, | ||
* that request will use the original base URL location information. | ||
* @experimental This feature is experimental and may be changed or removed. | ||
*/ | ||
updateBaseUrl(newUrl: string): Promise<void>; | ||
} | ||
} | ||
|
||
Object.defineProperty(App.prototype, "baseUrl", { | ||
get(this: App) { | ||
return this.internal.getBaseUrl(); | ||
}, | ||
set() { | ||
throw new Error("Cannot assign the base URL, please use 'updateBaseUrl()'."); | ||
}, | ||
}); | ||
|
||
App.prototype.updateBaseUrl = function (this: App, newUrl: string) { | ||
return this.internal.updateBaseUrl(newUrl); | ||
}; |