-
Notifications
You must be signed in to change notification settings - Fork 585
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* Refactored importer to take a client through config * Fixing tests to trigger client reset * Fixing tests after refactor
- Loading branch information
1 parent
21c932a
commit b473415
Showing
9 changed files
with
163 additions
and
96 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,46 +18,19 @@ | |
|
||
import Realm, { AppConfiguration } from "realm"; | ||
|
||
import { AppConfig, AppImporter, Credentials } from "@realm/app-importer"; | ||
import { AppConfig } from "@realm/app-importer"; | ||
import { mongodbServiceType } from "../utils/ExtendedAppConfigBuilder"; | ||
import { printWarningBox } from "../utils/print-warning-box"; | ||
import { baasAppImporter } from "../utils/baas-app-importer"; | ||
|
||
const REALM_LOG_LEVELS = ["all", "trace", "debug", "detail", "info", "warn", "error", "fatal", "off"]; | ||
|
||
const { | ||
syncLogLevel = "warn", | ||
baseUrl = "http://localhost:9090", | ||
reuseApp = false, | ||
username = "[email protected]", | ||
password = "password", | ||
publicKey, | ||
privateKey, | ||
missingServer, | ||
} = environment; | ||
const { syncLogLevel = "warn", baseUrl = "http://localhost:9090", missingServer } = environment; | ||
|
||
export { baseUrl }; | ||
|
||
const allowSkippingServerTests = typeof environment.baseUrl === "undefined" && missingServer !== false; | ||
|
||
const credentials: Credentials = | ||
typeof publicKey === "string" && typeof privateKey === "string" | ||
? { | ||
kind: "api-key", | ||
publicKey, | ||
privateKey, | ||
} | ||
: { | ||
kind: "username-password", | ||
username, | ||
password, | ||
}; | ||
|
||
const importer = new AppImporter({ | ||
baseUrl, | ||
credentials, | ||
reuseApp, | ||
}); | ||
|
||
function isConnectionRefused(err: unknown) { | ||
return ( | ||
err instanceof Error && | ||
|
@@ -105,7 +78,7 @@ export function importAppBefore( | |
throw new Error("Unexpected app on context, use only one importAppBefore per test"); | ||
} else { | ||
try { | ||
const { appId } = await importer.importApp(config); | ||
const { appId } = await baasAppImporter.importApp(config); | ||
this.app = new Realm.App({ id: appId, baseUrl, ...sdkConfig }); | ||
} catch (err) { | ||
if (isConnectionRefused(err) && allowSkippingServerTests) { | ||
|
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,42 @@ | ||
//////////////////////////////////////////////////////////////////////////// | ||
// | ||
// 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 { AdminApiClient, Credentials } from "@realm/app-importer"; | ||
|
||
const { | ||
baseUrl = "http://localhost:9090", | ||
username = "[email protected]", | ||
password = "password", | ||
publicKey, | ||
privateKey, | ||
} = environment; | ||
|
||
export const credentials: Credentials = | ||
typeof publicKey === "string" && typeof privateKey === "string" | ||
? { | ||
kind: "api-key", | ||
publicKey, | ||
privateKey, | ||
} | ||
: { | ||
kind: "username-password", | ||
username, | ||
password, | ||
}; | ||
|
||
export const baasAdminClient = new AdminApiClient({ baseUrl, credentials }); |
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,28 @@ | ||
//////////////////////////////////////////////////////////////////////////// | ||
// | ||
// 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 { AppImporter } from "@realm/app-importer"; | ||
|
||
import { baasAdminClient } from "./baas-admin-api"; | ||
|
||
const { reuseApp = false } = environment; | ||
|
||
export const baasAppImporter = new AppImporter({ | ||
client: baasAdminClient, | ||
reuseApp, | ||
}); |
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
Oops, something went wrong.