Skip to content
This repository has been archived by the owner on Oct 25, 2021. It is now read-only.

Commit

Permalink
Merge pull request #358 from Financial-Times/rhys/strip-test-on-publi…
Browse files Browse the repository at this point in the history
…sh-only
  • Loading branch information
wheresrhys authored Apr 8, 2021
2 parents 8331805 + 9c7d0b0 commit 549705b
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 15 deletions.
35 changes: 21 additions & 14 deletions packages/tc-schema-sdk/__tests__/test-schema-properties.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,48 +95,55 @@ const schemaFixture = {
};

describe('test schema properties', () => {
it('excludes test properties by default', async () => {
const schema = new SDK({ schemaData: { schema: schemaFixture } });
// Note that this behaviour is the opposite as tc-schema-publisher
// This is because, consider teh test environment:
// 1. tc-schema-publisher explicitly publishes including test properties
// 2. Now that they are in, we don't want any instance of the SDK running in a
// test app to strip them out again!
it('includes test properties by default', async () => {
const schema = new SDK({
schemaData: { schema: schemaFixture },
});
await schema.ready();
expect(schema.getTypes().length).toEqual(1);
expect(schema.getTypes().length).toEqual(2);
expect(schema.getTypes()[0].name).toEqual('TypeA');
expect(schema.getTypes()[1].name).toEqual('TypeB');
expect(Object.keys(schema.getTypes()[0].properties)).toEqual([
'code',
'stringPropertyA',
'stringPropertyB',
]);
expect(Object.keys(schema.getEnums())).toEqual(['AnEnum']);
expect(Object.keys(schema.getEnums())).toEqual(['AnEnum', 'ATestEnum']);
expect(Object.keys(schema.getTypes({ grouped: true }))).toEqual([
'prod',
'test',
]);
expect(schema.getTypes({ grouped: true }).prod.types[0].name).toEqual(
'TypeA',
);
expect(schema.getTypes({ grouped: true }).test.types[0].name).toEqual(
'TypeB',
);
});

it('includes test properties on demand', async () => {
it('excludes test properties on demand', async () => {
const schema = new SDK({
schemaData: { schema: schemaFixture },
includeTestDefinitions: true,
includeTestDefinitions: false,
});
await schema.ready();
expect(schema.getTypes().length).toEqual(2);
expect(schema.getTypes().length).toEqual(1);
expect(schema.getTypes()[0].name).toEqual('TypeA');
expect(schema.getTypes()[1].name).toEqual('TypeB');
expect(Object.keys(schema.getTypes()[0].properties)).toEqual([
'code',
'stringPropertyA',
'stringPropertyB',
]);
expect(Object.keys(schema.getEnums())).toEqual(['AnEnum', 'ATestEnum']);
expect(Object.keys(schema.getEnums())).toEqual(['AnEnum']);
expect(Object.keys(schema.getTypes({ grouped: true }))).toEqual([
'prod',
'test',
]);
expect(schema.getTypes({ grouped: true }).prod.types[0].name).toEqual(
'TypeA',
);
expect(schema.getTypes({ grouped: true }).test.types[0].name).toEqual(
'TypeB',
);
});
});
2 changes: 1 addition & 1 deletion packages/tc-schema-sdk/sdk.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const relationshipType = require('./data-accessors/relationship-type');
const { SchemaUpdater } = require('./lib/updater');
const utils = require('./lib/utils');

const defaultOptions = { includeTestDefinitions: false };
const defaultOptions = { includeTestDefinitions: true };

class SDK {
constructor(userOptions = {}) {
Expand Down

0 comments on commit 549705b

Please sign in to comment.