-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: fixed modelFirebaseFunctionMapFactory() short specifier
- added tests for modelFirebaseFunctionMapFactory()
- Loading branch information
Showing
2 changed files
with
95 additions
and
1 deletion.
There are no files selected for viewing
94 changes: 94 additions & 0 deletions
94
packages/firebase/src/lib/client/function/model.function.factory.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
import { Functions } from 'firebase/functions'; | ||
import { firestoreModelIdentity } from '../../common/firestore/collection/collection'; | ||
import { FirebaseFunctionTypeConfigMap } from './function.factory'; | ||
import { ModelFirebaseCreateFunction, ModelFirebaseCrudFunction, ModelFirebaseCrudFunctionConfigMap, ModelFirebaseFunctionMap, modelFirebaseFunctionMapFactory, ModelFirebaseReadFunction } from './model.function.factory'; | ||
|
||
/** | ||
* This is our FirebaseFunctionTypeMap for Example. It defines all the functions that are available. | ||
*/ | ||
export type ExampleFunctionTypeMap = {}; | ||
|
||
export const exampleFunctionTypeConfigMap: FirebaseFunctionTypeConfigMap<ExampleFunctionTypeMap> = {}; | ||
|
||
export const exampleIdentity = firestoreModelIdentity('example', 'e'); | ||
|
||
export type ExampleTypes = typeof exampleIdentity; | ||
|
||
export type ExampleModelCrudFunctionsConfig = { | ||
example: { | ||
read: { | ||
user: [object, boolean]; | ||
}; | ||
create: { | ||
_: object; | ||
user: object; | ||
}; | ||
update: { | ||
_: object; | ||
sendUserInvite: object; | ||
admin: object; | ||
}; | ||
delete: object; | ||
}; | ||
}; | ||
|
||
export const exampleModelCrudFunctionsConfig: ModelFirebaseCrudFunctionConfigMap<ExampleModelCrudFunctionsConfig, ExampleTypes> = { | ||
example: ['read:user', 'create:_,user', 'update:_,sendUserInvite,admin' as any, 'delete'] | ||
}; | ||
|
||
export abstract class ExampleFunctions implements ModelFirebaseFunctionMap<ExampleFunctionTypeMap, ExampleModelCrudFunctionsConfig> { | ||
abstract example: { | ||
createExample: { | ||
create: ModelFirebaseCreateFunction<object>; | ||
createExample: ModelFirebaseCreateFunction<object>; | ||
user: ModelFirebaseCreateFunction<object>; | ||
createExampleUser: ModelFirebaseCreateFunction<object>; | ||
}; | ||
readExample: { | ||
user: ModelFirebaseReadFunction<object, boolean>; | ||
readExampleUser: ModelFirebaseReadFunction<object, boolean>; | ||
}; | ||
updateExample: { | ||
update: ModelFirebaseCrudFunction<object>; | ||
updateExample: ModelFirebaseCrudFunction<object>; | ||
admin: ModelFirebaseCrudFunction<object>; | ||
updateExampleAdmin: ModelFirebaseCrudFunction<object>; | ||
sendUserInvite: ModelFirebaseCrudFunction<object>; | ||
updateExampleSendUserInvite: ModelFirebaseCrudFunction<object>; | ||
}; | ||
deleteExample: ModelFirebaseCrudFunction<object>; | ||
}; | ||
} | ||
|
||
/** | ||
* Used to generate our ExampleFunctionMap for a Functions instance. | ||
*/ | ||
export const exampleFunctionMap = modelFirebaseFunctionMapFactory(exampleFunctionTypeConfigMap, exampleModelCrudFunctionsConfig); | ||
|
||
describe('modelFirebaseFunctionMapFactory()', () => { | ||
it('should create the expected functions.', () => { | ||
const functionsInstance: Functions = undefined as unknown as Functions; | ||
|
||
const result = exampleFunctionMap(functionsInstance) as ExampleFunctions; | ||
|
||
expect(result.example.createExample).toBeDefined(); | ||
expect(result.example.createExample.create).toBeDefined(); | ||
expect(result.example.createExample.createExample).toBeDefined(); | ||
expect(result.example.createExample.user).toBeDefined(); | ||
expect(result.example.createExample.createExampleUser).toBeDefined(); | ||
|
||
expect(result.example.readExample).toBeDefined(); | ||
expect(result.example.readExample.user).toBeDefined(); | ||
expect(result.example.readExample.readExampleUser).toBeDefined(); | ||
|
||
expect(result.example.updateExample).toBeDefined(); | ||
expect(result.example.updateExample.update).toBeDefined(); | ||
expect(result.example.updateExample.updateExample).toBeDefined(); | ||
expect(result.example.updateExample.admin).toBeDefined(); | ||
expect(result.example.updateExample.updateExampleAdmin).toBeDefined(); | ||
expect(result.example.updateExample.sendUserInvite).toBeDefined(); | ||
expect(result.example.updateExample.updateExampleSendUserInvite).toBeDefined(); | ||
|
||
expect(result.example.deleteExample).toBeDefined(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters