Skip to content

Commit

Permalink
Update tests to skip in CI
Browse files Browse the repository at this point in the history
  • Loading branch information
cbullinger committed May 4, 2024
1 parent 87e45e9 commit a27b2f1
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 61 deletions.
40 changes: 22 additions & 18 deletions examples/dart/test/app_services_test.dart
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
import "dart:html_common";

import 'package:test/test.dart';
import 'package:realm_dart/realm.dart';
import "dart:io";
import "dart:convert";
import "dart:isolate";
import 'utils.dart';

void main() {
const APP_ID = "example-testers-kvjdy";
const EDGE_SERVER_APP_ID = "edge-server-npqxd";
const EDGE_SERVER_APP_ID = "sync-edge-server-cskhoow";
const baseUrl = 'http://localhost';
const newBaseUrl = 'https://services.cloud.mongodb.com';

group('App Services client - ', () {
test('Access App client', () {
Expand All @@ -33,36 +34,39 @@ void main() {
});

test('Custom BaseUrl', () {
// :snippet-start: import-experimental
@Experimental()
// :snippet-end:
// :snippet-start: custom-base-url
// Specify a baseUrl to connect to a server other than the default.
// In this case, an Edge Server instance running on the device.
final appConfig = AppConfiguration(EDGE_SERVER_APP_ID,
baseUrl: Uri.parse('http://localhost:80'));
// :snippet-start: custom-base-url
// Specify a baseUrl to connect to a server other than the default
final appConfig =
AppConfiguration(APP_ID, baseUrl: Uri.parse('https://example.com'));

var app = App(appConfig);
// :snippet-end:
expect(app.baseUrl.toString(), 'http://localhost:80');
expect(app.baseUrl.toString(), 'https://example.com');
});

test('Change BaseUrl', () {
@Experimental()
test('Change BaseUrl', () async {
// :snippet-start: change-base-url
// Specify a custom baseUrl to connect to.
// In this case,
final appConfig = AppConfiguration(EDGE_SERVER_APP_ID,
baseUrl: Uri.parse('http://localhost:80'));

var app = App(appConfig);
expect(app.baseUrl.toString(), 'http://localhost:80'); // :remove:

// ... log in a user and use the app ...
// :remove-start:
expect(app.baseUrl.toString(), baseUrl);
await app.logIn(Credentials.anonymous());
expect(app.currentUser != null, true);
// :remove-end:

// Later, change the baseUrl to a different server
app.updateBaseUrl(Uri.parse('https://services.cloud.mongodb.com'));
// Later, change the baseUrl to the default: https://services.cloud.mongodb.com
await app.updateBaseUrl(null);
// :snippet-end:
});
expect(app.baseUrl.toString(), newBaseUrl);
},
skip:
"""Skipping until we get Edge Server running in a CI and we can write automated tests for full flow (this was tested locally and succeeded)""");

test('Access App on background isolate by id', () async {
// :snippet-start: access-app-by-id
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
// Specify a custom baseUrl to connect to.
// In this case,
final appConfig = AppConfiguration(EDGE_SERVER_APP_ID,
baseUrl: Uri.parse('http://localhost:80'));

var app = App(appConfig);

// ... log in a user and use the app ...

// Later, change the baseUrl to a different server
app.updateBaseUrl(Uri.parse('https://services.cloud.mongodb.com'));
// Later, change the baseUrl to the default: https://services.cloud.mongodb.com
await app.updateBaseUrl(null);
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
// Specify a baseUrl to connect to a server other than the default.
// In this case, an Edge Server instance running on the device.
final appConfig = AppConfiguration(EDGE_SERVER_APP_ID,
baseUrl: Uri.parse('http://localhost:80'));
// Specify a baseUrl to connect to a server other than the default
final appConfig =
AppConfiguration(APP_ID, baseUrl: Uri.parse('https://example.com'));

var app = App(appConfig);

This file was deleted.

72 changes: 36 additions & 36 deletions source/sdk/flutter/app-services/connect-to-app.txt
Original file line number Diff line number Diff line change
Expand Up @@ -36,44 +36,44 @@ Access the App Client
.. versionchanged:: 1.7.0
``App`` must be created on the main isolate.

Create an ``App`` instance to access App Services features throughout your
client application. We recommend that you create the ``App`` instance only
Create an ``App`` instance to access App Services features throughout your
client application. We recommend that you create the ``App`` instance only
once on the main isolate, ideally as soon as the app starts.

#. Get your App Services App's ID from the App Services UI. To learn how,
#. Get your App Services App's ID from the App Services UI. To learn how,
refer to :ref:`Find your App ID <find-your-app-id>`.
#. Create an :flutter-sdk:`AppConfiguration <realm/AppConfiguration-class.html>`
object with your App's App ID as the argument.
#. Create an :flutter-sdk:`App <realm/App-class.html>`
with the ``AppConfiguration`` you just created. In Flutter v1.7.0 and later,
this must be done on the main isolate, otherwise the SDK throws an error.
with the ``AppConfiguration`` you just created. In Flutter v1.7.0 and later,
this must be done on the main isolate, otherwise the SDK throws an error.

After you create the ``App``, you can access the constructed ``App`` instance
After you create the ``App``, you can access the constructed ``App`` instance
on a background isolate using ``App.getById``. Refer to the
:ref:`Get App by ID <flutter-get-app-by-id>` section on this page for more
:ref:`Get App by ID <flutter-get-app-by-id>` section on this page for more
information.

.. literalinclude:: /examples/generated/flutter/app_services_test.snippet.access-app-client.dart
:language: dart

You can create multiple App client instances to connect to multiple
Apps. All App client instances that share the same App ID use the same
Apps. All App client instances that share the same App ID use the same
underlying connection.

.. important:: Changing an App Config After Initializing the App

.. versionchanged:: 1.8.0
``baseUrl`` is not cached in the ``AppConfiguration``
When you initialize the App client, the configuration is cached internally.

When you initialize the App client, the configuration is cached internally.
Attempting to close and then re-open an App with a changed configuration
within the same process has no effect. The client continues to use the
cached configuration.
within the same process has no effect. The client continues to use the
cached configuration.

In Flutter SDK version 1.8.0 and later, the :flutter-sdk:`baseUrl <realm/AppConfiguration/baseUrl.html>`
is *no longer* cached in the App configuration. This means that you can change the
``baseUrl``, and the App client will use the updated configuration. In
earlier SDK versions, changes to the ``baseUrl`` in a cached App
In Flutter SDK version 1.8.0 and later, the :flutter-sdk:`baseUrl <realm/AppConfiguration/baseUrl.html>`
is *no longer* cached in the App configuration. This means that you can change the
``baseUrl``, and the App client will use the updated configuration. In
earlier SDK versions, changes to the ``baseUrl`` in a cached App
configuration have no effect.

.. _flutter-app-client-configuration:
Expand All @@ -91,7 +91,7 @@ To learn about the available configuration options, refer to the
:flutter-sdk:`AppConfiguration <realm/AppConfiguration-class.html>` reference documentation.

.. literalinclude:: /examples/generated/flutter/app_services_test.snippet.app-client-advanced-configuration.dart
:language: dart
:language: dart

.. note:: Connect Using Android 7 or Older

Expand All @@ -107,8 +107,8 @@ Get App by ID

.. versionadded:: 1.7.0

After you have created an ``App`` instance on the main isolate, you can access
the constructed instance on a background isolate by passing the App ID to the
After you have created an ``App`` instance on the main isolate, you can access
the constructed instance on a background isolate by passing the App ID to the
:flutter-sdk:`App.getById() <realm/App/getById.html>` method. Then, you can use it to work with the ``App`` and users as needed.

.. literalinclude:: /examples/generated/flutter/app_services_test.snippet.access-app-by-id.dart
Expand All @@ -128,35 +128,34 @@ connect to a different server:
- You want to connect to an Edge Server instance. For more information, refer to
the :ref:`edge-server-connect-from-client` App Services documentation.

You can specify a ``baseUrl`` in the
You can specify a ``baseUrl`` in the
:flutter-sdk:`AppConfiguration <realm/AppConfiguration-class.html>`:

.. literalinclude:: /examples/generated/code/start/RealmApp.snippet.custom-base-url.swift
:language: swift
.. literalinclude:: /examples/generated/flutter/app_services_test.snippet.custom-base-url.dart
:language: dart

Connect to a Different Server During Runtime
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

.. versionadded:: 2.2.0
.. versionadded:: 1.8.0
.. versionchanged:: 2.2.0
``updateBaseUrl`` accepts ``null`` value

In some cases, you might want to change the ``baseUrl`` while the app is
running. For example, you might want to roam between Edge Servers or
move from an App Services connection to an Edge Server connection.
move from an App Services connection to an Edge Server connection.

To change the ``baseUrl`` during runtime, call the
:flutter-sdk:`app.updateBaseUrl <realm/App/updateBaseUrl.html>` method:
To change the ``baseUrl`` during runtime, call the experimental
:flutter-sdk:`app.updateBaseUrl <realm/App/updateBaseUrl.html>` method. You can
pass ``null`` to reset the ``baseUrl`` to the default value.

.. literalinclude:: /examples/generated/code/start/RealmApp.snippet.change-base-url.swift
:language: swift

This API is experimental, so you must use the ``@experimental`` import in the
file where you want to use this API:
.. literalinclude:: /examples/generated/flutter/app_services_test.snippet.change-base-url.dart
:language: dart

.. literalinclude:: /examples/generated/code/start/RealmApp.snippet.import-experimental.swift
:language: swift
This API is experimental and may change in future releases.

Change ``baseUrl`` After Opening Synced Database with User
``````````````````````````````````````````````````````````
Change Server with Logged-In User
`````````````````````````````````

If you want to change the ``baseUrl`` after you have logged in a user and
have opened a synced database, the app must perform a client reset. For more
Expand All @@ -170,4 +169,5 @@ Perform the following in your code:
4. Open a synced database pulling data from the new server

Both the server and the client *must* be online for the user to authenticate and
connect to the new server. If the server is not online or the client does not have a network connection, the user cannot authenticate and open the database.
connect to the new server. If the server is not online or the client does not
have a network connection, the user cannot authenticate and open the database.

0 comments on commit a27b2f1

Please sign in to comment.