mirror of
https://github.com/datahub-project/datahub.git
synced 2025-08-14 04:06:45 +00:00
21 lines
930 B
TypeScript
21 lines
930 B
TypeScript
![]() |
import { Server } from 'ember-cli-mirage';
|
||
|
import { IMirageSchemaRegistry } from 'ember-cli-mirage/types/registries/schema';
|
||
|
|
||
|
/**
|
||
|
* Serializes the Mirage Schema models from the instance of the supplied Mirage Server
|
||
|
* Useful in Ember Rendering or Unit tests that need to extract a value from the Mirage DB without making
|
||
|
* a request to a Mirage endpoint
|
||
|
* @template M
|
||
|
* @param {M} modelName the name of the Mirage Model to serialize instances
|
||
|
* @param {Server} server reference to the Mirage server instance, typically this.server in a MirageTestContext
|
||
|
*/
|
||
|
export const getSerializedMirageModel = <K extends keyof IMirageSchemaRegistry>(
|
||
|
modelName: K,
|
||
|
server: Server
|
||
|
): Array<IMirageSchemaRegistry[K]> => {
|
||
|
const serializer = server.serializerOrRegistry.serializerFor(modelName);
|
||
|
const models = server.schema[modelName as string].all();
|
||
|
|
||
|
return serializer.serialize(models) as Array<IMirageSchemaRegistry[K]>;
|
||
|
};
|