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

RJS-2847: Trying to reproduce RJS-2847 #6774

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Changes from all 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
83 changes: 82 additions & 1 deletion integration-tests/tests/src/tests/objects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
//
////////////////////////////////////////////////////////////////////////////
import { expect } from "chai";
import Realm, { BSON, UpdateMode } from "realm";
import Realm, { BSON, ClientResetMode, UpdateMode } from "realm";

import { IPerson, Person, PersonSchema } from "../schemas/person-and-dogs";
import {
Expand Down Expand Up @@ -368,6 +368,45 @@
linkingObjectsCol: IAllTypes[];
}

class TrackingData extends Realm.Object {
id!: number;
progress!: number;

static schema: Realm.ObjectSchema = {
name: 'TrackingData',

Check failure on line 376 in integration-tests/tests/src/tests/objects.ts

View workflow job for this annotation

GitHub Actions / Lint

Replace `↹name:·'TrackingData'` with `····name:·"TrackingData"`
primaryKey: 'id',

Check failure on line 377 in integration-tests/tests/src/tests/objects.ts

View workflow job for this annotation

GitHub Actions / Lint

Replace `↹primaryKey:·'id'` with `····primaryKey:·"id"`
properties: {

Check failure on line 378 in integration-tests/tests/src/tests/objects.ts

View workflow job for this annotation

GitHub Actions / Lint

Replace `↹` with `····`
id: 'int',

Check failure on line 379 in integration-tests/tests/src/tests/objects.ts

View workflow job for this annotation

GitHub Actions / Lint

Replace `↹··id:·'int'` with `······id:·"int"`
progress: 'int',

Check failure on line 380 in integration-tests/tests/src/tests/objects.ts

View workflow job for this annotation

GitHub Actions / Lint

Replace `↹··progress:·'int'` with `······progress:·"int"`
},

Check failure on line 381 in integration-tests/tests/src/tests/objects.ts

View workflow job for this annotation

GitHub Actions / Lint

Replace `↹` with `····`
};
}

class Profile extends Realm.Object {
id!: string;
attemptID!: number;
lastAccessDate!: Date | null;
trackingDataList!: TrackingData[];
sortOrder!: number;
from!: Date;
userId!: string;

static schema: Realm.ObjectSchema = {
name: 'Profile',

Check failure on line 395 in integration-tests/tests/src/tests/objects.ts

View workflow job for this annotation

GitHub Actions / Lint

Replace `↹name:·'Profile'` with `····name:·"Profile"`
primaryKey: 'id',

Check failure on line 396 in integration-tests/tests/src/tests/objects.ts

View workflow job for this annotation

GitHub Actions / Lint

Replace `↹primaryKey:·'id'` with `····primaryKey:·"id"`

properties: {

Check failure on line 398 in integration-tests/tests/src/tests/objects.ts

View workflow job for this annotation

GitHub Actions / Lint

Replace `↹` with `····`
id: 'string',

Check failure on line 399 in integration-tests/tests/src/tests/objects.ts

View workflow job for this annotation

GitHub Actions / Lint

Replace `↹··id:·'string'` with `······id:·"string"`
attemptID: 'int',
lastAccessDate: {type: 'date', optional: true},
trackingDataList: 'TrackingData[]',
sortOrder: 'int',
from: 'date',
userId: 'string',
},
};
}

describe("Realm.Object", () => {
describe("Methods", () => {
it("linkingObjects works with both string and type input", () => {
Expand Down Expand Up @@ -1520,4 +1559,46 @@
});
}
});

// from https://github.com/realm/realm-js/issues/6758
describe("spread operator", () => {
openRealmBeforeEach({ schema: [Profile, TrackingData] });

it("nested objects", function (this: RealmContext) {
const trackingData = {
"id": 1,
"progress": 50,
} as TrackingData;

const currentProfile = {
"id": "12345_2_2",
"attemptID": 2,
"lastAccessDate": null,
"trackingDataList": [trackingData],
"sortOrder": 1,
"from": new Date("2024-06-10T10:27:02.909Z"),
"userId": "12345"
} as Profile;

this.realm.write(() => {
this.realm.create<Profile>(Profile, currentProfile);
});

const currentObjects = this.realm.objects<Profile>(Profile);
expect(currentObjects.length).equals(1);
expect(currentObjects[0].trackingDataList.length).equals(1);
expect(currentObjects[0].trackingDataList[0].progress).equals(50);

const updatedProfile = { ...currentProfile, lastAccessDate: new Date() };

this.realm.write(() => {
this.realm.create<Profile>(Profile, updatedProfile, Realm.UpdateMode.Modified);
});

const updatedObjects = this.realm.objects<Profile>(Profile);
expect(updatedObjects.length).equals(1);
expect(updatedObjects[0].trackingDataList.length).equals(1);
expect(updatedObjects[0].trackingDataList[0].progress).equals(50);
});
});
});
Loading