From cd5aeb3b89bca27551cc5cb6375c741ef4c74959 Mon Sep 17 00:00:00 2001 From: Convly Date: Mon, 4 Mar 2024 14:46:23 +0100 Subject: [PATCH] chore: fix tests broken by naming changes in imports and namespaces --- .../generators/schemas/attributes.test.js | 98 +++++++++---------- .../generators/schemas/utils.test.js | 6 +- 2 files changed, 52 insertions(+), 52 deletions(-) diff --git a/packages/utils/typescript/lib/__tests__/generators/schemas/attributes.test.js b/packages/utils/typescript/lib/__tests__/generators/schemas/attributes.test.js index 372853a144..d2e3efae3d 100644 --- a/packages/utils/typescript/lib/__tests__/generators/schemas/attributes.test.js +++ b/packages/utils/typescript/lib/__tests__/generators/schemas/attributes.test.js @@ -48,7 +48,7 @@ describe('Attributes', () => { expect(prop.type.types).toHaveLength(1); expect(prop.type.types[0].kind).toBe(ts.SyntaxKind.TypeReference); - expect(prop.type.types[0].typeName.escapedText).toBe('Attribute.String'); + expect(prop.type.types[0].typeName.escapedText).toBe('Schema.Attribute.String'); expect(prop.type.types[0].typeArguments).toBeUndefined(); }); @@ -60,7 +60,7 @@ describe('Attributes', () => { expect(prop.type.types).toHaveLength(1); expect(prop.type.types[0].kind).toBe(ts.SyntaxKind.TypeReference); - expect(prop.type.types[0].typeName.escapedText).toBe('Attribute.Component'); + expect(prop.type.types[0].typeName.escapedText).toBe('Schema.Attribute.Component'); expect(prop.type.types[0].typeArguments).toHaveLength(2); expect(prop.type.types[0].typeArguments[0].kind).toBe(ts.SyntaxKind.StringLiteral); expect(prop.type.types[0].typeArguments[0].text).toBe('default.comp'); @@ -83,14 +83,14 @@ describe('Attributes', () => { const [attributeType, requiredOptionType] = prop.type.types; expect(attributeType.kind).toBe(ts.SyntaxKind.TypeReference); - expect(attributeType.typeName.escapedText).toBe('Attribute.Enumeration'); + expect(attributeType.typeName.escapedText).toBe('Schema.Attribute.Enumeration'); expect(attributeType.typeArguments).toHaveLength(1); expect(attributeType.typeArguments[0].kind).toBe(ts.SyntaxKind.TupleType); expect(attributeType.typeArguments[0].elements[0].text).toBe('a'); expect(attributeType.typeArguments[0].elements[1].text).toBe('b'); expect(requiredOptionType.kind).toBe(ts.SyntaxKind.TypeReference); - expect(requiredOptionType.typeName.escapedText).toBe('Attribute.DefaultTo'); + expect(requiredOptionType.typeName.escapedText).toBe('Schema.Attribute.DefaultTo'); expect(requiredOptionType.typeArguments).toHaveLength(1); expect(requiredOptionType.typeArguments[0].kind).toBe(ts.SyntaxKind.StringLiteral); expect(requiredOptionType.typeArguments[0].text).toBe('b'); @@ -109,22 +109,22 @@ describe('Attributes', () => { }); test.each([ - ['string', 'Attribute.String'], - ['text', 'Attribute.Text'], - ['richtext', 'Attribute.RichText'], - ['password', 'Attribute.Password'], - ['email', 'Attribute.Email'], - ['date', 'Attribute.Date'], - ['time', 'Attribute.Time'], - ['datetime', 'Attribute.DateTime'], - ['timestamp', 'Attribute.Timestamp'], - ['integer', 'Attribute.Integer'], - ['biginteger', 'Attribute.BigInteger'], - ['float', 'Attribute.Float'], - ['decimal', 'Attribute.Decimal'], - ['boolean', 'Attribute.Boolean'], - ['json', 'Attribute.JSON'], - ['media', 'Attribute.Media'], + ['string', 'Schema.Attribute.String'], + ['text', 'Schema.Attribute.Text'], + ['richtext', 'Schema.Attribute.RichText'], + ['password', 'Schema.Attribute.Password'], + ['email', 'Schema.Attribute.Email'], + ['date', 'Schema.Attribute.Date'], + ['time', 'Schema.Attribute.Time'], + ['datetime', 'Schema.Attribute.DateTime'], + ['timestamp', 'Schema.Attribute.Timestamp'], + ['integer', 'Schema.Attribute.Integer'], + ['biginteger', 'Schema.Attribute.BigInteger'], + ['float', 'Schema.Attribute.Float'], + ['decimal', 'Schema.Attribute.Decimal'], + ['boolean', 'Schema.Attribute.Boolean'], + ['json', 'Schema.Attribute.JSON'], + ['media', 'Schema.Attribute.Media'], ])('Basic %p attribute should map to a %p type', (type, expectedType) => { const typeNode = getAttributeType('foo', { type }); @@ -135,7 +135,7 @@ describe('Attributes', () => { expect(typeNode.typeArguments).toBeUndefined(); expect(consoleWarnMock).not.toHaveBeenCalled(); - expect(addImport).toHaveBeenCalledWith('Attribute'); + expect(addImport).toHaveBeenCalledWith('Schema'); }); describe('Complex types (with generic type parameters)', () => { @@ -146,7 +146,7 @@ describe('Attributes', () => { expect(typeNode.typeName.escapedText).toBe(typeName); expect(consoleWarnMock).not.toHaveBeenCalled(); - expect(addImport).toHaveBeenCalledWith('Attribute'); + expect(addImport).toHaveBeenCalledWith('Schema'); }; describe('Enumeration', () => { @@ -154,7 +154,7 @@ describe('Attributes', () => { const attribute = { type: 'enumeration', enum: ['a', 'b', 'c'] }; const typeNode = getAttributeType('foo', attribute); - defaultAssertions(typeNode, 'Attribute.Enumeration'); + defaultAssertions(typeNode, 'Schema.Attribute.Enumeration'); expect(typeNode.typeArguments).toHaveLength(1); expect(typeNode.typeArguments[0].kind).toBe(ts.SyntaxKind.TupleType); @@ -175,7 +175,7 @@ describe('Attributes', () => { const attribute = { type: 'uid' }; const typeNode = getAttributeType('foo', attribute); - defaultAssertions(typeNode, 'Attribute.UID'); + defaultAssertions(typeNode, 'Schema.Attribute.UID'); expect(typeNode.typeArguments).toBeUndefined(); }); @@ -184,7 +184,7 @@ describe('Attributes', () => { const attribute = { type: 'uid', targetField: 'bar' }; const typeNode = getAttributeType('foo', attribute, 'api::bar.bar'); - defaultAssertions(typeNode, 'Attribute.UID'); + defaultAssertions(typeNode, 'Schema.Attribute.UID'); expect(typeNode.typeArguments).not.toBeUndefined(); expect(typeNode.typeArguments).toHaveLength(1); @@ -197,7 +197,7 @@ describe('Attributes', () => { const attribute = { type: 'uid', options: { separator: '_' } }; const typeNode = getAttributeType('foo', attribute, 'api::foo.foo'); - defaultAssertions(typeNode, 'Attribute.UID'); + defaultAssertions(typeNode, 'Schema.Attribute.UID'); expect(typeNode.typeArguments).toHaveLength(2); @@ -221,7 +221,7 @@ describe('Attributes', () => { const attribute = { type: 'uid', options: { separator: '_' }, targetField: 'bar' }; const typeNode = getAttributeType('foo', attribute, 'api::bar.bar'); - defaultAssertions(typeNode, 'Attribute.UID'); + defaultAssertions(typeNode, 'Schema.Attribute.UID'); expect(typeNode.typeArguments).toHaveLength(2); @@ -248,7 +248,7 @@ describe('Attributes', () => { const attribute = { type: 'relation', relation: 'oneToOne', target: 'api::bar.bar' }; const typeNode = getAttributeType('foo', attribute, 'api::foo.foo'); - defaultAssertions(typeNode, 'Attribute.Relation'); + defaultAssertions(typeNode, 'Schema.Attribute.Relation'); expect(typeNode.typeArguments).toHaveLength(2); @@ -263,7 +263,7 @@ describe('Attributes', () => { const attribute = { type: 'relation', relation: 'morphMany' }; const typeNode = getAttributeType('foo', attribute, 'api::foo.foo'); - defaultAssertions(typeNode, 'Attribute.Relation'); + defaultAssertions(typeNode, 'Schema.Attribute.Relation'); expect(typeNode.typeArguments).toHaveLength(1); @@ -277,7 +277,7 @@ describe('Attributes', () => { const attribute = { type: 'component', component: 'default.comp', repeatable: true }; const typeNode = getAttributeType('foo', attribute); - defaultAssertions(typeNode, 'Attribute.Component'); + defaultAssertions(typeNode, 'Schema.Attribute.Component'); expect(typeNode.typeArguments).toHaveLength(2); @@ -291,7 +291,7 @@ describe('Attributes', () => { const attribute = { type: 'component', component: 'default.comp' }; const typeNode = getAttributeType('foo', attribute); - defaultAssertions(typeNode, 'Attribute.Component'); + defaultAssertions(typeNode, 'Schema.Attribute.Component'); expect(typeNode.typeArguments).toHaveLength(2); @@ -307,7 +307,7 @@ describe('Attributes', () => { const attribute = { type: 'dynamiczone', components: ['default.comp1', 'default.comp2'] }; const typeNode = getAttributeType('foo', attribute); - defaultAssertions(typeNode, 'Attribute.DynamicZone'); + defaultAssertions(typeNode, 'Schema.Attribute.DynamicZone'); expect(typeNode.typeArguments).toHaveLength(1); @@ -349,7 +349,7 @@ describe('Attributes', () => { expect(modifiers).toHaveLength(1); expect(modifiers[0].kind).toBe(ts.SyntaxKind.TypeReference); - expect(modifiers[0].typeName.escapedText).toBe('Attribute.Required'); + expect(modifiers[0].typeName.escapedText).toBe('Schema.Attribute.Required'); }); }); @@ -374,7 +374,7 @@ describe('Attributes', () => { expect(modifiers).toHaveLength(1); expect(modifiers[0].kind).toBe(ts.SyntaxKind.TypeReference); - expect(modifiers[0].typeName.escapedText).toBe('Attribute.Private'); + expect(modifiers[0].typeName.escapedText).toBe('Schema.Attribute.Private'); }); }); @@ -399,7 +399,7 @@ describe('Attributes', () => { expect(modifiers).toHaveLength(1); expect(modifiers[0].kind).toBe(ts.SyntaxKind.TypeReference); - expect(modifiers[0].typeName.escapedText).toBe('Attribute.Unique'); + expect(modifiers[0].typeName.escapedText).toBe('Schema.Attribute.Unique'); }); }); @@ -424,7 +424,7 @@ describe('Attributes', () => { expect(modifiers).toHaveLength(1); expect(modifiers[0].kind).toBe(ts.SyntaxKind.TypeReference); - expect(modifiers[0].typeName.escapedText).toBe('Attribute.Configurable'); + expect(modifiers[0].typeName.escapedText).toBe('Schema.Attribute.Configurable'); }); }); @@ -445,7 +445,7 @@ describe('Attributes', () => { expect(modifiers).toHaveLength(1); expect(modifiers[0].kind).toBe(ts.SyntaxKind.TypeReference); - expect(modifiers[0].typeName.escapedText).toBe('Attribute.CustomField'); + expect(modifiers[0].typeName.escapedText).toBe('Schema.Attribute.CustomField'); expect(modifiers[0].typeArguments).toHaveLength(1); expect(modifiers[0].typeArguments[0].kind).toBe(ts.SyntaxKind.StringLiteral); expect(modifiers[0].typeArguments[0].text).toBe('plugin::color-picker.color'); @@ -463,7 +463,7 @@ describe('Attributes', () => { expect(modifiers).toHaveLength(1); expect(modifiers[0].kind).toBe(ts.SyntaxKind.TypeReference); - expect(modifiers[0].typeName.escapedText).toBe('Attribute.CustomField'); + expect(modifiers[0].typeName.escapedText).toBe('Schema.Attribute.CustomField'); expect(modifiers[0].typeArguments).toHaveLength(2); expect(modifiers[0].typeArguments[0].kind).toBe(ts.SyntaxKind.StringLiteral); expect(modifiers[0].typeArguments[0].text).toBe('plugin::color-picker.color'); @@ -497,7 +497,7 @@ describe('Attributes', () => { expect(modifiers).toHaveLength(1); expect(modifiers[0].kind).toBe(ts.SyntaxKind.TypeReference); - expect(modifiers[0].typeName.escapedText).toBe('Attribute.SetPluginOptions'); + expect(modifiers[0].typeName.escapedText).toBe('Schema.Attribute.SetPluginOptions'); expect(modifiers[0].typeArguments).toHaveLength(1); expect(modifiers[0].typeArguments[0].kind).toBe(ts.SyntaxKind.TypeLiteral); expect(modifiers[0].typeArguments[0].members).toHaveLength(1); @@ -536,7 +536,7 @@ describe('Attributes', () => { expect(modifiers).toHaveLength(1); expect(modifiers[0].kind).toBe(ts.SyntaxKind.TypeReference); - expect(modifiers[0].typeName.escapedText).toBe('Attribute.SetMinMax'); + expect(modifiers[0].typeName.escapedText).toBe('Schema.Attribute.SetMinMax'); const [setMinMax] = modifiers; const { typeArguments } = setMinMax; @@ -568,7 +568,7 @@ describe('Attributes', () => { expect(modifiers).toHaveLength(1); expect(modifiers[0].kind).toBe(ts.SyntaxKind.TypeReference); - expect(modifiers[0].typeName.escapedText).toBe('Attribute.SetMinMax'); + expect(modifiers[0].typeName.escapedText).toBe('Schema.Attribute.SetMinMax'); const [setMinMax] = modifiers; const { typeArguments } = setMinMax; @@ -600,7 +600,7 @@ describe('Attributes', () => { expect(modifiers).toHaveLength(1); expect(modifiers[0].kind).toBe(ts.SyntaxKind.TypeReference); - expect(modifiers[0].typeName.escapedText).toBe('Attribute.SetMinMax'); + expect(modifiers[0].typeName.escapedText).toBe('Schema.Attribute.SetMinMax'); const [setMinMax] = modifiers; const { typeArguments } = setMinMax; @@ -637,7 +637,7 @@ describe('Attributes', () => { expect(modifiers).toHaveLength(1); expect(modifiers[0].kind).toBe(ts.SyntaxKind.TypeReference); - expect(modifiers[0].typeName.escapedText).toBe('Attribute.SetMinMax'); + expect(modifiers[0].typeName.escapedText).toBe('Schema.Attribute.SetMinMax'); const [setMinMax] = modifiers; const { typeArguments } = setMinMax; @@ -669,7 +669,7 @@ describe('Attributes', () => { expect(modifiers).toHaveLength(1); expect(modifiers[0].kind).toBe(ts.SyntaxKind.TypeReference); - expect(modifiers[0].typeName.escapedText).toBe('Attribute.SetMinMax'); + expect(modifiers[0].typeName.escapedText).toBe('Schema.Attribute.SetMinMax'); const [setMinMax] = modifiers; const { typeArguments } = setMinMax; @@ -710,7 +710,7 @@ describe('Attributes', () => { expect(modifiers).toHaveLength(1); expect(modifiers[0].kind).toBe(ts.SyntaxKind.TypeReference); - expect(modifiers[0].typeName.escapedText).toBe('Attribute.SetMinMaxLength'); + expect(modifiers[0].typeName.escapedText).toBe('Schema.Attribute.SetMinMaxLength'); expect(modifiers[0].typeArguments).toHaveLength(1); expect(modifiers[0].typeArguments[0].kind).toBe(ts.SyntaxKind.TypeLiteral); @@ -734,7 +734,7 @@ describe('Attributes', () => { expect(modifiers).toHaveLength(1); expect(modifiers[0].kind).toBe(ts.SyntaxKind.TypeReference); - expect(modifiers[0].typeName.escapedText).toBe('Attribute.SetMinMaxLength'); + expect(modifiers[0].typeName.escapedText).toBe('Schema.Attribute.SetMinMaxLength'); expect(modifiers[0].typeArguments).toHaveLength(1); expect(modifiers[0].typeArguments[0].kind).toBe(ts.SyntaxKind.TypeLiteral); @@ -758,7 +758,7 @@ describe('Attributes', () => { expect(modifiers).toHaveLength(1); expect(modifiers[0].kind).toBe(ts.SyntaxKind.TypeReference); - expect(modifiers[0].typeName.escapedText).toBe('Attribute.SetMinMaxLength'); + expect(modifiers[0].typeName.escapedText).toBe('Schema.Attribute.SetMinMaxLength'); expect(modifiers[0].typeArguments).toHaveLength(1); expect(modifiers[0].typeArguments[0].kind).toBe(ts.SyntaxKind.TypeLiteral); @@ -800,7 +800,7 @@ describe('Attributes', () => { expect(modifiers).toHaveLength(1); expect(modifiers[0].kind).toBe(ts.SyntaxKind.TypeReference); - expect(modifiers[0].typeName.escapedText).toBe('Attribute.DefaultTo'); + expect(modifiers[0].typeName.escapedText).toBe('Schema.Attribute.DefaultTo'); expect(modifiers[0].typeArguments).toHaveLength(1); expect(modifiers[0].typeArguments[0].kind).toBe(ts.SyntaxKind.TrueKeyword); @@ -813,7 +813,7 @@ describe('Attributes', () => { expect(modifiers).toHaveLength(1); expect(modifiers[0].kind).toBe(ts.SyntaxKind.TypeReference); - expect(modifiers[0].typeName.escapedText).toBe('Attribute.DefaultTo'); + expect(modifiers[0].typeName.escapedText).toBe('Schema.Attribute.DefaultTo'); expect(modifiers[0].typeArguments).toHaveLength(1); expect(modifiers[0].typeArguments[0].kind).toBe(ts.SyntaxKind.TypeLiteral); diff --git a/packages/utils/typescript/lib/__tests__/generators/schemas/utils.test.js b/packages/utils/typescript/lib/__tests__/generators/schemas/utils.test.js index a0b9444a7d..e7bbdfb976 100644 --- a/packages/utils/typescript/lib/__tests__/generators/schemas/utils.test.js +++ b/packages/utils/typescript/lib/__tests__/generators/schemas/utils.test.js @@ -120,9 +120,9 @@ describe('Utils', () => { describe('Get Schema Extends Type Name', () => { test.each([ - [{ modelType: 'component', kind: null }, 'Schema.Component'], - [{ modelType: 'contentType', kind: 'singleType' }, 'Schema.SingleType'], - [{ modelType: 'contentType', kind: 'collectionType' }, 'Schema.CollectionType'], + [{ modelType: 'component', kind: null }, 'Struct.ComponentSchema'], + [{ modelType: 'contentType', kind: 'singleType' }, 'Struct.SingleTypeSchema'], + [{ modelType: 'contentType', kind: 'collectionType' }, 'Struct.CollectionTypeSchema'], [{ modelType: 'invalidType', kind: 'foo' }, null], ])("Expect %p to generate %p as the base type for a schema's interface", (schema, expected) => { expect(getSchemaExtendsTypeName(schema)).toBe(expected);