Skip to content

Commit

Permalink
Fix adapter findHasMany test stub functions (#296)
Browse files Browse the repository at this point in the history
  • Loading branch information
charlesfries authored Apr 23, 2024
1 parent c4978c0 commit 8fb9328
Showing 1 changed file with 38 additions and 16 deletions.
54 changes: 38 additions & 16 deletions tests/unit/adapters/cloud-firestore-modular-test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
/*
eslint
max-classes-per-file: off
*/

import { module, test } from 'qunit';
import { setupTest } from 'ember-qunit';
import EmberObject from '@ember/object';

import Store from '@ember-data/store';
import { CollectionReference, Firestore, WriteBatch } from 'firebase/firestore';
import sinon from 'sinon';

Expand Down Expand Up @@ -354,19 +360,24 @@ module('Unit | Adapter | cloud firestore modular', function (hooks) {
module('function: findHasMany', function () {
test('should fetch many-to-one cardinality', async function (assert) {
// Arrange
const determineRelationshipTypeStub = sinon.stub().returns('manyToOne');
const inverseForStub = sinon.stub().returns({ name: 'author' });
this.owner.register('service:store', class extends Store {
modelFor() {
return {
determineRelationshipType: determineRelationshipTypeStub,
inverseFor: inverseForStub,
};
}
});

const store = this.owner.lookup('service:store');
store.normalize = sinon.stub();
store.push = sinon.stub();
const determineRelationshipTypeStub = sinon.stub().returns('manyToOne');
const inverseForStub = sinon.stub().returns({ name: 'author' });
const snapshot = {
id: 'user_a',
modelName: 'user',
record: EmberObject.create(),
type: {
determineRelationshipType: determineRelationshipTypeStub,
inverseFor: inverseForStub,
},
};
const url = 'posts';
const relationship = {
Expand All @@ -392,17 +403,23 @@ module('Unit | Adapter | cloud firestore modular', function (hooks) {

test('should fetch many-to-whatever cardinality', async function (assert) {
// Arrange
const determineRelationshipTypeStub = sinon.stub().returns('manyToNone');
this.owner.register('service:store', class extends Store {
modelFor() {
return {
determineRelationshipType: determineRelationshipTypeStub,
};
}
});

const store = this.owner.lookup('service:store');
store.normalize = sinon.stub();
store.push = sinon.stub();
const determineRelationshipTypeStub = sinon.stub().returns('manyToNone');
const snapshot = {
modelName: 'user',
record: EmberObject.create({
referenceTo: doc(db, 'users/user_a'),
}),
type: {
determineRelationshipType: determineRelationshipTypeStub,
},
};
const url = 'users/user_a/friends';
const relationship = {
Expand Down Expand Up @@ -432,21 +449,26 @@ module('Unit | Adapter | cloud firestore modular', function (hooks) {

test('should be able to fetch with filter using a record property', async function (assert) {
// Arrange
const determineRelationshipTypeStub = sinon.stub().returns('manyToOne');
const inverseForStub = sinon.stub().returns({ name: 'author' });
this.owner.register('service:store', class extends Store {
modelFor() {
return {
determineRelationshipType: determineRelationshipTypeStub,
inverseFor: inverseForStub,
};
}
});

const store = this.owner.lookup('service:store');
store.normalize = sinon.stub();
store.push = sinon.stub();
const determineRelationshipTypeStub = sinon.stub().returns('manyToOne');
const inverseForStub = sinon.stub().returns({ name: 'author' });
const snapshot = {
id: 'user_a',
modelName: 'user',
record: EmberObject.create({
id: 'user_a',
}),
type: {
determineRelationshipType: determineRelationshipTypeStub,
inverseFor: inverseForStub,
},
};
const url = 'posts';
const relationship = {
Expand Down

0 comments on commit 8fb9328

Please sign in to comment.