Hi!
I’m currently setting up a fresh Parse project (piggy backing off a previous setup) which has Jest installed for testing.
I’m currently writing a bunch of a integration tests, to try out a multi-tenant setup…
We’re using Typescript (for better or worse - I’m very much still learning it)… Anyway, In our project, we have a models.ts
file where we define interfaces for what we want our classes to look like. Then, we have a dao.ts
file where we extend the Parse object and register the models as sub classes.
I’m grouping functionality into specific files - e.g. tenant, roles, user, etc, into a auth.ts file and here I import what I need from my dao file. - e.g. of dao file:
import { Tenant } from './models'
export class TenantDAO extends Parse.Object {
constructor(attributes: Tenant) {
super('Tenant', attributes)
}
}
When I import this auth file into my cloud code file and make queries via the api, everything works as expected. E.g. I can make parse queries and use the master key in the cloud code and it works.
Now, in my test file, I’m setting parse up along with the usual config - e.g.:
import Parse from 'parse/node'
import { ParseObjects, TenantDAO, UserDAO } from '../../src/dao'
describe('API Integration (CRUD) Tests', () => {
beforeEach(() => {
Parse.initialize(config.parse.appId)
;(Parse as any).serverURL = `${config.parse.serverUrl}/parse`
;(Parse as any).masterKey = config.parse.masterKey
;(Parse as any).cloud = `../../src/${config.parse.cloudFunctions}`
ParseObjects.register() // registering my Parse objects...
})
...
I’m importing Parse here, I’m registering my Parse Objects, but when I run the tests, I get a Parse is not defined
error, pointing to where I’m extending Parse in my dao file.
I thought all good, I would just import Parse here. When I do, the tests seem to run, but then it complains about the lack of the master key.
My guess is that I’m missing something related to how I’m initialising Parse, but I’m just not quite sure.
I’d really appreciate any guidance.
Thanks!