kossnocorp / typesaurus

🦕 Type-safe TypeScript-first ODM for Firestore
https://typesaurus.com
415 stars 36 forks source link

Does injectTestingAdaptor() actually work with '@firebase/rules-unit-testing'? #112

Closed jimlloyd closed 6 months ago

jimlloyd commented 2 years ago

I see that in v7.2 changes were made to replace the deprecated @firebase/testing package with @firebase/rules-unit-testing but I am confused by the change. It seems to me that merely changing

import * as testing from '@firebase/testing'

to

import * as testing from '@firebase/rules-unit-testing'

and then continuing to use

 injectTestingAdaptor(testing.initializeAdminApp({ projectId: 'project-id' }))

should fail as the API changed and initializeAdminApp() no longer exists. The documentation has not been updated to show what is the correct way to initialize now and I do not see any tests. Is injectTestingAdaptor() still supported?

I had guess that perhaps I should use something like this:

import { initializeTestEnvironment, RulesTestEnvironment, RulesTestContext, TestEnvironmentConfig } from '@firebase/rules-unit-testing';
const rulesTestEnvironment: RulesTestEnvironment = await initializeTestEnvironment(config);
injectTestingAdaptor(rulesTestEnvironment.authenticatedContext('admin'));

But that fails with the error TypeError: Cannot read property 'DocumentReference' of undefined inside injectTestingAdaptor when creating the AdaptorConsts with this code:

    {
      DocumentReference: testing.firestore.DocumentReference,
      Timestamp: testing.firestore.Timestamp,
      FieldPath: testing.firestore.FieldPath,
      FieldValue: testing.firestore.FieldValue
    }

testing here is as above. There is no firestore member in the API exposed by '@firebase/rules-unit-testing'.

Note: I am using @SrBrahma's fork (installed via yarn add typesaurus@srbrahma/typesaurus#lib) but the the source for injectTestingAdapter is identical to the master branch here. (https://github.com/kossnocorp/typesaurus/blob/7ec7091da299592751bca055bc7158e0d8ccaa2a/src/testing/index.ts#L38)

kossnocorp commented 6 months ago

I believe it's not relevant anymore in v10. If it is, please open a separate issue with repro. Thanks!