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

chore: pass Store service objects in tests #284

Merged
merged 1 commit into from
Apr 22, 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
57 changes: 38 additions & 19 deletions tests/unit/adapters/cloud-firestore-modular-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,11 @@ module('Unit | Adapter | cloud firestore modular', function (hooks) {
module('function: generateIdForRecord', function () {
test('should generate ID for record', function (assert) {
// Arrange
const store = this.owner.lookup('service:store');
const adapter = this.owner.lookup('adapter:cloud-firestore-modular');

// Act
const result = adapter.generateIdForRecord({}, 'foo');
const result = adapter.generateIdForRecord(store, 'foo');

// Assert
assert.strictEqual(typeof result, 'string');
Expand All @@ -44,7 +45,7 @@ module('Unit | Adapter | cloud firestore modular', function (hooks) {
module('function: createRecord', function () {
test('should proxy a call to updateRecord and return with the created doc', async function (assert) {
// Arrange
const store = {};
const store = this.owner.lookup('service:store');
const modelClass = { modelName: 'user' };
const snapshot = { id: 'user_100', age: 30, username: 'user_100' };
const adapter = this.owner.lookup('adapter:cloud-firestore-modular');
Expand All @@ -63,7 +64,7 @@ module('Unit | Adapter | cloud firestore modular', function (hooks) {
module('function: updateRecord', function () {
test('should update record and resolve with the updated doc', async function (assert) {
// Arrange
const store = {};
const store = this.owner.lookup('service:store');
const modelClass = { modelName: 'user' };
const snapshot = {
id: 'user_a',
Expand All @@ -90,7 +91,7 @@ module('Unit | Adapter | cloud firestore modular', function (hooks) {

test('should update record in a custom collection and resolve with the updated resource', async function (assert) {
// Arrange
const store = {};
const store = this.owner.lookup('service:store');
const modelClass = { modelName: 'user' };
const snapshot = {
id: 'user_a',
Expand Down Expand Up @@ -118,7 +119,7 @@ module('Unit | Adapter | cloud firestore modular', function (hooks) {

test('should update record and process additional batched writes', async function (assert) {
// Arrange
const store = {};
const store = this.owner.lookup('service:store');
const modelClass = { modelName: 'user' };
const snapshot = {
id: 'user_a',
Expand Down Expand Up @@ -153,7 +154,7 @@ module('Unit | Adapter | cloud firestore modular', function (hooks) {
module('function: deleteRecord', function () {
test('should delete record', async function (assert) {
// Arrange
const store = {};
const store = this.owner.lookup('service:store');
const modelClass = { modelName: 'user' };
const snapshot = { id: 'user_a' };
const adapter = this.owner.lookup('adapter:cloud-firestore-modular');
Expand All @@ -169,7 +170,7 @@ module('Unit | Adapter | cloud firestore modular', function (hooks) {

test('should delete record in a custom collection', async function (assert) {
// Arrange
const store = {};
const store = this.owner.lookup('service:store');
const modelClass = { modelName: 'post' };
const snapshot = {
id: 'post_b',
Expand All @@ -193,7 +194,7 @@ module('Unit | Adapter | cloud firestore modular', function (hooks) {

test('should delete record and process additional batched writes', async function (assert) {
// Arrange
const store = {};
const store = this.owner.lookup('service:store');
const modelClass = { modelName: 'user' };
const snapshot = {
id: 'user_a',
Expand Down Expand Up @@ -224,7 +225,9 @@ module('Unit | Adapter | cloud firestore modular', function (hooks) {
module('function: findAll', function () {
test('should fetch all records for a model', async function (assert) {
// Arrange
const store = { normalize: sinon.stub(), push: sinon.stub() };
const store = this.owner.lookup('service:store');
store.normalize = sinon.stub();
store.push = sinon.stub();
const modelClass = { modelName: 'user' };
const adapter = this.owner.lookup('adapter:cloud-firestore-modular');

Expand Down Expand Up @@ -258,7 +261,9 @@ module('Unit | Adapter | cloud firestore modular', function (hooks) {
module('function: findRecord', function () {
test('should fetch a record', async function (assert) {
// Arrange
const store = { normalize: sinon.stub(), push: sinon.stub() };
const store = this.owner.lookup('service:store');
store.normalize = sinon.stub();
store.push = sinon.stub();
const modelClass = { modelName: 'user' };
const modelId = 'user_a';
const snapshot = {};
Expand All @@ -278,7 +283,9 @@ module('Unit | Adapter | cloud firestore modular', function (hooks) {

test('should fetch a record in a custom collection', async function (assert) {
// Arrange
const store = { normalize: sinon.stub(), push: sinon.stub() };
const store = this.owner.lookup('service:store');
store.normalize = sinon.stub();
store.push = sinon.stub();
const modelClass = { modelName: 'user' };
const modelId = 'user_a';
const snapshot = {
Expand All @@ -301,7 +308,9 @@ module('Unit | Adapter | cloud firestore modular', function (hooks) {
// Arrange
assert.expect(2);

const store = { normalize: sinon.stub(), push: sinon.stub() };
const store = this.owner.lookup('service:store');
store.normalize = sinon.stub();
store.push = sinon.stub();
const modelClass = { modelName: 'user' };
const modelId = 'user_100';
const snapshot = {};
Expand All @@ -321,7 +330,9 @@ module('Unit | Adapter | cloud firestore modular', function (hooks) {
module('function: findBelongsTo', function () {
test('should fetch a belongs to record', async function (assert) {
// Arrange
const store = { normalize: sinon.stub(), push: sinon.stub() };
const store = this.owner.lookup('service:store');
store.normalize = sinon.stub();
store.push = sinon.stub();
const snapshot = {};
const url = 'users/user_a';
const relationship = { type: 'user', options: {} };
Expand All @@ -343,7 +354,9 @@ module('Unit | Adapter | cloud firestore modular', function (hooks) {
module('function: findHasMany', function () {
test('should fetch many-to-one cardinality', async function (assert) {
// Arrange
const store = { normalize: sinon.stub(), push: sinon.stub() };
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 = {
Expand Down Expand Up @@ -379,7 +392,9 @@ module('Unit | Adapter | cloud firestore modular', function (hooks) {

test('should fetch many-to-whatever cardinality', async function (assert) {
// Arrange
const store = { normalize: sinon.stub(), push: sinon.stub() };
const store = this.owner.lookup('service:store');
store.normalize = sinon.stub();
store.push = sinon.stub();
const determineRelationshipTypeStub = sinon.stub().returns('manyToNone');
const snapshot = {
record: EmberObject.create({
Expand Down Expand Up @@ -417,7 +432,9 @@ 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 store = { normalize: sinon.stub(), push: sinon.stub() };
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 = {
Expand Down Expand Up @@ -455,7 +472,9 @@ module('Unit | Adapter | cloud firestore modular', function (hooks) {

test('should be able to fetch with a custom reference', async function (assert) {
// Arrange
const store = { normalize: sinon.stub(), push: sinon.stub() };
const store = this.owner.lookup('service:store');
store.normalize = sinon.stub();
store.push = sinon.stub();
const snapshot = {
record: EmberObject.create({ id: 'user_a' }),
};
Expand Down Expand Up @@ -487,7 +506,7 @@ module('Unit | Adapter | cloud firestore modular', function (hooks) {
module('function: query', function () {
test('should query for records', async function (assert) {
// Arrange
const store = {};
const store = this.owner.lookup('service:store');
const modelClass = { modelName: 'user' };
const queryRef = {
filter(reference: CollectionReference) {
Expand All @@ -512,7 +531,7 @@ module('Unit | Adapter | cloud firestore modular', function (hooks) {

test('should query for records in a custom collection', async function (assert) {
// Arrange
const store = {};
const store = this.owner.lookup('service:store');
const modelClass = { modelName: 'user' };
const queryRef = {
buildReference(firestore: Firestore) {
Expand Down
Loading