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

feat: add test for serializer extractRelationships method #300

Merged
merged 1 commit into from
Apr 24, 2024
Merged
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
31 changes: 31 additions & 0 deletions tests/unit/serializers/cloud-firestore-modular-test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { module, test } from 'qunit';
import { setupTest } from 'ember-qunit';

import CloudFirestoreSerializer from 'ember-cloud-firestore-adapter/serializers/cloud-firestore-modular';

module('Unit | Serializer | cloud-firestore modular', function (hooks) {
setupTest(hooks);

Expand Down Expand Up @@ -31,5 +33,34 @@ module('Unit | Serializer | cloud-firestore modular', function (hooks) {
});
});

module('extractRelationships()', function () {
test('should return object containing manyToMany and manyToOne links', function (assert) {
// Arrange
const serializer = this.owner.lookup('serializer:cloud-firestore-modular') as CloudFirestoreSerializer;
const store = this.owner.lookup('service:store');
serializer.store = store; // TODO: injected store on serializer is undefined in tests

// Act
const result = serializer.extractRelationships(store.modelFor('user'), {
id: 'user_a',
links: {},
});

// Assert
assert.deepEqual(result, {
groups: {
links: {
related: 'users/user_a/groups',
},
},
posts: {
links: {
related: 'posts',
},
},
});
});
});

// NOTE: Other public methods are hard to test because they rely on private APIs from ember-data
});
Loading