Skip to content

Commit

Permalink
clean up test files
Browse files Browse the repository at this point in the history
  • Loading branch information
wolfgangwalther committed Nov 5, 2019
1 parent 5197b2e commit 062a433
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 48 deletions.
71 changes: 36 additions & 35 deletions test/schema-manager.test.js
Expand Up @@ -151,6 +151,7 @@ describe('SchemaManager', function() {
const strategy = new JsonSchema7Strategy();
const schema = schemaManager.generate(models.user, strategy, {
include: ['STRING', 'STRING_1234'],
associations: false,
});

it(`include attribute STRING`, function() {
Expand All @@ -162,7 +163,7 @@ describe('SchemaManager', function() {
});

it(`do not include other attributes`, function() {
expect(Object.keys(schema.properties).length).toBe(4); // 2 left + 1 HasOne + 1 HasMany
expect(Object.keys(schema.properties).length).toBe(2);
});
});

Expand All @@ -174,11 +175,11 @@ describe('SchemaManager', function() {
const strategy = new JsonSchema7Strategy();
const schema = schemaManager.generate(models.user, strategy);

it(`generates HasOne association property 'profile'`, function() {
it(`generates association property 'profile'`, function() {
expect(schema.properties).toHaveProperty('profile');
});

it(`generates HasMany association property 'documents'`, function() {
it(`generates association property 'documents'`, function() {
expect(schema.properties).toHaveProperty('documents');
});
});
Expand All @@ -190,51 +191,51 @@ describe('SchemaManager', function() {
associations: false,
});

it(`does not generate HasOne association property 'profile'`, function() {
it(`does not generate association property 'profile'`, function() {
expect(schema.properties.profile).toBeUndefined();
});

it(`does not generate HasMany association property 'documents'`, function() {
it(`does not generate association property 'documents'`, function() {
expect(schema.properties.documents).toBeUndefined();
});
});
});

// ------------------------------------------------------------------------
// make sure option 'includeAssociations'functions as expected
// ------------------------------------------------------------------------
describe('Ensure association inclusions:', function() {
const schemaManager = new JsonSchemaManager();
const strategy = new JsonSchema7Strategy();
const schema = schemaManager.generate(models.user, strategy, {
includeAssociations: ['profile'],
});
// ------------------------------------------------------------------------
// make sure option 'includeAssociations'functions as expected
// ------------------------------------------------------------------------
describe('Ensure association inclusions:', function() {
const schemaManager = new JsonSchemaManager();
const strategy = new JsonSchema7Strategy();
const schema = schemaManager.generate(models.user, strategy, {
includeAssociations: ['profile'],
});

it(`include association 'profile'`, function() {
expect(schema.properties).toHaveProperty('profile');
});
it(`include association 'profile'`, function() {
expect(schema.properties).toHaveProperty('profile');
});

it(`do not include association 'documents'`, function() {
expect(schema.properties.documents).toBeUndefined();
it(`do not include association 'documents'`, function() {
expect(schema.properties.documents).toBeUndefined();
});
});
});

// ------------------------------------------------------------------------
// make sure option 'excludeAssociations'functions as expected
// ------------------------------------------------------------------------
describe('Ensure association exclusions:', function() {
const schemaManager = new JsonSchemaManager();
const strategy = new JsonSchema7Strategy();
const schema = schemaManager.generate(models.user, strategy, {
excludeAssociations: ['profile'],
});
// ------------------------------------------------------------------------
// make sure option 'excludeAssociations'functions as expected
// ------------------------------------------------------------------------
describe('Ensure association exclusions:', function() {
const schemaManager = new JsonSchemaManager();
const strategy = new JsonSchema7Strategy();
const schema = schemaManager.generate(models.user, strategy, {
excludeAssociations: ['profile'],
});

it(`do not include association 'profile'`, function() {
expect(schema.properties.profile).toBeUndefined();
});
it(`do not include association 'profile'`, function() {
expect(schema.properties.profile).toBeUndefined();
});

it(`include association 'documents'`, function() {
expect(schema.properties).toHaveProperty('documents');
it(`include association 'documents'`, function() {
expect(schema.properties).toHaveProperty('documents');
});
});
});
});
26 changes: 13 additions & 13 deletions test/strategies/openapi-v3-stragegy.test.js
Expand Up @@ -20,19 +20,19 @@ describe('OpenApi3Strategy', function() {
disableComments: false,
});
const strategy = new OpenApi3Strategy();
const userSchema = schemaManager.generate(models.user, strategy);
const schema = schemaManager.generate(models.user, strategy);

// ------------------------------------------------------------------------
// make sure sequelize DataTypes render as expected
// ------------------------------------------------------------------------
describe('Ensure Sequelize DataTypes are properly converted and thus:', function() {
describe('STRING_ALLOWNULL', function() {
it("has property 'type' of type 'string'", function() {
expect(userSchema.properties.STRING_ALLOWNULL.type).toEqual('string');
expect(schema.properties.STRING_ALLOWNULL.type).toEqual('string');
});

it("has property 'nullable' of type 'boolean'", function() {
expect(typeof userSchema.properties.STRING_ALLOWNULL.nullable).toEqual('boolean');
expect(typeof schema.properties.STRING_ALLOWNULL.nullable).toEqual('boolean');
});
});
});
Expand All @@ -43,19 +43,19 @@ describe('OpenApi3Strategy', function() {
describe('Ensure custom Sequelize attribute options render as expected and thus:', function() {
describe('CUSTOM_DESCRIPTION', function() {
it(`has property 'description' with the expected string value`, function() {
expect(userSchema.properties.CUSTOM_DESCRIPTION.description).toEqual(
expect(schema.properties.CUSTOM_DESCRIPTION.description).toEqual(
'Custom attribute description',
);
});
});

describe('CUSTOM_EXAMPLES', function() {
it("has property 'example' of type 'array'", function() {
expect(Array.isArray(userSchema.properties.CUSTOM_EXAMPLES.example)).toBe(true);
expect(Array.isArray(schema.properties.CUSTOM_EXAMPLES.example)).toBe(true);
});

it('with the two expected string values', function() {
expect(userSchema.properties.CUSTOM_EXAMPLES.example).toEqual([
expect(schema.properties.CUSTOM_EXAMPLES.example).toEqual([
'Custom example 1',
'Custom example 2',
]);
Expand All @@ -64,13 +64,13 @@ describe('OpenApi3Strategy', function() {

describe('CUSTOM_READONLY', function() {
it(`has property 'readOnly' with value 'true'`, function() {
expect(userSchema.properties.CUSTOM_READONLY.readOnly).toEqual(true);
expect(schema.properties.CUSTOM_READONLY.readOnly).toEqual(true);
});
});

describe('CUSTOM_WRITEONLY', function() {
it(`has property 'writeOnly' with value 'true'`, function() {
expect(userSchema.properties.CUSTOM_WRITEONLY.writeOnly).toEqual(true);
expect(schema.properties.CUSTOM_WRITEONLY.writeOnly).toEqual(true);
});
});
});
Expand All @@ -81,21 +81,21 @@ describe('OpenApi3Strategy', function() {
describe('Ensure associations are properly generated and thus:', function() {
describe("user.HasOne(profile) generates singular property 'profile' with:", function() {
it("property '$ref' pointing to plural '#/components/schemas/profiles'", function() {
expect(userSchema.properties.profile.$ref).toEqual('#/components/schemas/profiles');
expect(schema.properties.profile.$ref).toEqual('#/components/schemas/profiles');
});
});

describe("user.HasMany(document) generates plural property 'documents' with:", function() {
it("property 'type' with value 'array'", function() {
expect(userSchema.properties.documents.type).toEqual('array');
expect(schema.properties.documents.type).toEqual('array');
});

it("property 'items.oneOf' of type 'array'", function() {
expect(Array.isArray(userSchema.properties.documents.items.oneOf)).toBe(true);
expect(Array.isArray(schema.properties.documents.items.oneOf)).toBe(true);
});

it("array 'items.oneOf' holding an object with '$ref' pointing to plural '#/components/schemas/documents'", function() {
expect(userSchema.properties.documents.items.oneOf[0]).toEqual({
expect(schema.properties.documents.items.oneOf[0]).toEqual({
$ref: '#/components/schemas/documents', // eslint-disable-line unicorn/prevent-abbreviations
});
});
Expand All @@ -109,7 +109,7 @@ describe('OpenApi3Strategy', function() {
// the $refs will not resolve causing the validation to fail.
// ------------------------------------------------------------------------
describe('Ensure that the resultant document:', function() {
schemaWrapper.components.schemas.users = userSchema;
schemaWrapper.components.schemas.users = schema;
schemaWrapper.components.schemas.profiles = schemaManager.generate(models.profile, strategy);
schemaWrapper.components.schemas.documents = schemaManager.generate(
models.document,
Expand Down

0 comments on commit 062a433

Please sign in to comment.