mirror of
https://github.com/strapi/strapi.git
synced 2025-07-19 07:02:26 +00:00
67 lines
1.3 KiB
JavaScript
67 lines
1.3 KiB
JavaScript
![]() |
'use strict';
|
||
|
|
||
|
const { mergeSchemas } = require('../utils');
|
||
|
|
||
|
const createRootSchema = () => ({
|
||
|
definition: '',
|
||
|
resolvers: {},
|
||
|
query: {},
|
||
|
mutation: {},
|
||
|
});
|
||
|
|
||
|
describe('Utils', () => {
|
||
|
describe('mergeSchemas', () => {
|
||
|
test('Ignore empty schema', () => {
|
||
|
const rootSchema = createRootSchema();
|
||
|
mergeSchemas(rootSchema, {});
|
||
|
|
||
|
expect(rootSchema).toEqual(createRootSchema());
|
||
|
});
|
||
|
|
||
|
test('Concatenates definitions', () => {
|
||
|
const rootSchema = createRootSchema();
|
||
|
mergeSchemas(rootSchema, {
|
||
|
definition: 'type Query {}',
|
||
|
});
|
||
|
|
||
|
expect(rootSchema).toMatchObject({
|
||
|
definition: '\ntype Query {}',
|
||
|
});
|
||
|
});
|
||
|
|
||
|
test('merges resolvers', () => {
|
||
|
const resolvers = {
|
||
|
Post: {
|
||
|
id: () => {},
|
||
|
},
|
||
|
};
|
||
|
|
||
|
const rootSchema = createRootSchema();
|
||
|
mergeSchemas(rootSchema, {
|
||
|
resolvers,
|
||
|
});
|
||
|
|
||
|
expect(rootSchema.resolvers).toEqual(resolvers);
|
||
|
});
|
||
|
|
||
|
test('merges query and mutation', () => {
|
||
|
const query = {
|
||
|
posts() {},
|
||
|
};
|
||
|
|
||
|
const mutation = {
|
||
|
createMutation() {},
|
||
|
};
|
||
|
|
||
|
const rootSchema = createRootSchema();
|
||
|
mergeSchemas(rootSchema, {
|
||
|
query,
|
||
|
mutation,
|
||
|
});
|
||
|
|
||
|
expect(rootSchema.query).toEqual(query);
|
||
|
expect(rootSchema.mutation).toEqual(mutation);
|
||
|
});
|
||
|
});
|
||
|
});
|