Skip to content

Commit

Permalink
feat: add test for serializer extractRelationships method (#300)
Browse files Browse the repository at this point in the history
  • Loading branch information
charlesfries authored Apr 24, 2024
1 parent 031751f commit c81711b
Showing 1 changed file with 31 additions and 0 deletions.
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
});

0 comments on commit c81711b

Please sign in to comment.