-
Notifications
You must be signed in to change notification settings - Fork 559
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
140 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,24 @@ | ||
//////////////////////////////////////////////////////////////////////////// | ||
// | ||
// 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. | ||
// | ||
//////////////////////////////////////////////////////////////////////////// | ||
|
||
// This file is needed as a workaround for Metro unexpectedly failing | ||
// to use the entry point defined in the package.json `exports` field, | ||
// despite enabling `unstable_enablePackageExports`. | ||
|
||
/* 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,48 @@ | ||
//////////////////////////////////////////////////////////////////////////// | ||
// | ||
// 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. | ||
* @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. | ||
* @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); | ||
}; |