mirror of
https://github.com/strapi/strapi.git
synced 2025-11-02 02:44:55 +00:00
fix formatting
This commit is contained in:
parent
2e7cc82064
commit
c5053842fa
@ -4,15 +4,15 @@ import { Readable } from 'stream';
|
||||
* Collect every entity in a Readable stream
|
||||
*/
|
||||
export const collect = <T = unknown>(stream: Readable): Promise<T[]> => {
|
||||
const chunks: T[] = [];
|
||||
const chunks: T[] = [];
|
||||
|
||||
return new Promise((resolve) => {
|
||||
stream.on('data', (chunk) => chunks.push(chunk));
|
||||
stream.on('end', () => {
|
||||
stream.destroy();
|
||||
resolve(chunks);
|
||||
});
|
||||
return new Promise((resolve) => {
|
||||
stream.on('data', (chunk) => chunks.push(chunk));
|
||||
stream.on('end', () => {
|
||||
stream.destroy();
|
||||
resolve(chunks);
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
@ -20,16 +20,16 @@ export const collect = <T = unknown>(stream: Readable): Promise<T[]> => {
|
||||
* given params and cast it to the correct type
|
||||
*/
|
||||
export const getStrapiFactory =
|
||||
<
|
||||
T extends {
|
||||
[key in keyof Partial<Strapi.Strapi>]: unknown;
|
||||
}
|
||||
>(
|
||||
properties?: T
|
||||
) =>
|
||||
() => {
|
||||
return { ...properties } as Strapi.Strapi;
|
||||
};
|
||||
<
|
||||
T extends {
|
||||
[key in keyof Partial<Strapi.Strapi>]: unknown;
|
||||
}
|
||||
>(
|
||||
properties?: T
|
||||
) =>
|
||||
() => {
|
||||
return { ...properties } as Strapi.Strapi;
|
||||
};
|
||||
|
||||
/**
|
||||
* Union type used to represent the default content types available
|
||||
@ -40,38 +40,38 @@ export type ContentType = 'foo' | 'bar';
|
||||
* Factory to get default content types test values
|
||||
*/
|
||||
export const getContentTypes = (): {
|
||||
[key in ContentType]: { uid: key; attributes: { [attribute: string]: unknown } };
|
||||
[key in ContentType]: { uid: key; attributes: { [attribute: string]: unknown } };
|
||||
} => ({
|
||||
foo: { uid: 'foo', attributes: { title: { type: 'string' } } },
|
||||
bar: { uid: 'bar', attributes: { age: { type: 'number' } } },
|
||||
foo: { uid: 'foo', attributes: { title: { type: 'string' } } },
|
||||
bar: { uid: 'bar', attributes: { age: { type: 'number' } } },
|
||||
});
|
||||
|
||||
/**
|
||||
* Create a factory of readable streams (wrapped with a jest mock function)
|
||||
*/
|
||||
export const createMockedReadableFactory = <T extends string = ContentType>(source: {
|
||||
[ct in T]: Array<{ id: number;[key: string]: unknown }>;
|
||||
[ct in T]: Array<{ id: number; [key: string]: unknown }>;
|
||||
}) =>
|
||||
jest.fn((uid: T) => {
|
||||
return Readable.from(source[uid] || []);
|
||||
});
|
||||
jest.fn((uid: T) => {
|
||||
return Readable.from(source[uid] || []);
|
||||
});
|
||||
|
||||
/**
|
||||
* Create a factory of mocked query builders
|
||||
*/
|
||||
export const createMockedQueryBuilder = <T extends string = ContentType>(data: {
|
||||
[key in T]: unknown[];
|
||||
[key in T]: unknown[];
|
||||
}) =>
|
||||
jest.fn((uid: T) => {
|
||||
const state: { [key: string]: unknown } = { populate: undefined };
|
||||
jest.fn((uid: T) => {
|
||||
const state: { [key: string]: unknown } = { populate: undefined };
|
||||
|
||||
return {
|
||||
populate(populate: unknown) {
|
||||
state.populate = populate;
|
||||
return this;
|
||||
},
|
||||
stream() {
|
||||
return Readable.from(data[uid]);
|
||||
},
|
||||
};
|
||||
});
|
||||
return {
|
||||
populate(populate: unknown) {
|
||||
state.populate = populate;
|
||||
return this;
|
||||
},
|
||||
stream() {
|
||||
return Readable.from(data[uid]);
|
||||
},
|
||||
};
|
||||
});
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user