From 8f65cc640ff1f87228851129ffca478f12f6ef31 Mon Sep 17 00:00:00 2001 From: Fran Mendez Date: Fri, 3 Nov 2023 15:40:39 +0100 Subject: [PATCH] feat!: remove messageId() --- src/models/message-trait.ts | 1 - src/models/v2/message-trait.ts | 6 +--- src/models/v3/message-trait.ts | 8 ++---- src/spec-types/v3.ts | 1 - .../custom-operations/apply-traits-v3.spec.ts | 20 ++++++------- test/models/v2/channel.spec.ts | 6 ++-- test/models/v2/message-trait.spec.ts | 4 +-- test/models/v2/server.spec.ts | 14 +++++----- test/models/v3/channel.spec.ts | 10 +++---- test/models/v3/message-trait.spec.ts | 28 +++---------------- test/models/v3/message.spec.ts | 6 ---- test/models/v3/operation-reply.spec.ts | 8 +++--- test/models/v3/operation.spec.ts | 12 ++++---- test/models/v3/server.spec.ts | 16 +++++------ 14 files changed, 52 insertions(+), 88 deletions(-) diff --git a/src/models/message-trait.ts b/src/models/message-trait.ts index 8abb1f18e..3e16104a2 100644 --- a/src/models/message-trait.ts +++ b/src/models/message-trait.ts @@ -9,7 +9,6 @@ export interface MessageTraitInterface extends BaseModel, BindingsMixinInterface hasSchemaFormat(): boolean; schemaFormat(): string | undefined; hasMessageId(): boolean; - messageId(): string | undefined; hasCorrelationId(): boolean; correlationId(): CorrelationIdInterface | undefined; hasContentType(): boolean; diff --git a/src/models/v2/message-trait.ts b/src/models/v2/message-trait.ts index cee11664a..fb327f615 100644 --- a/src/models/v2/message-trait.ts +++ b/src/models/v2/message-trait.ts @@ -21,7 +21,7 @@ import type { v2 } from '../../spec-types'; export class MessageTrait extends BaseModel implements MessageTraitInterface { id(): string { - return this.messageId() || this._meta.id || this.json(xParserMessageName) as string; + return this._json.messageId || this._meta.id || this.json(xParserMessageName) as string; } hasSchemaFormat(): boolean { @@ -35,10 +35,6 @@ export class MessageTrait extends CoreModel implements MessageTraitInterface { id(): string { - return this.messageId() || this._meta.id || this.extensions().get(xParserMessageName)?.value() as string; + return this._meta.id || this.extensions().get(xParserMessageName)?.value() as string; } hasMessageId(): boolean { - return !!this._json.messageId; + return false; } hasSchemaFormat(): boolean { @@ -29,10 +29,6 @@ export class MessageTrait({ messages: { someMessage: { messageId: 'messageId' } } }); + const doc = serializeInput({ messages: { someMessage: {} } }); const d = new Channel(doc); const msg = doc.messages?.['someMessage'] as v3.MessageObject; expect(d.messages()).toBeInstanceOf(Messages); expect(d.messages().all()).toHaveLength(1); expect(d.messages().all()[0]).toBeInstanceOf(Message); - expect(d.messages().all()[0].messageId()).toEqual(msg?.messageId); + expect(d.messages().all()[0].id()).toEqual('someMessage'); }); it('should return collection of messages - more than one messages', function() { - const doc = serializeInput({ messages: { someMessage1: { messageId: 'messageId1' }, someMessage2: { messageId: 'messageId2' } } }); + const doc = serializeInput({ messages: { someMessage1: {}, someMessage2: {} } }); const d = new Channel(doc); const msg1 = doc.messages?.['someMessage1'] as v3.MessageObject; const msg2 = doc.messages?.['someMessage2'] as v3.MessageObject; expect(d.messages()).toBeInstanceOf(Messages); expect(d.messages().all()).toHaveLength(2); expect(d.messages().all()[0]).toBeInstanceOf(Message); - expect(d.messages().all()[0].id()).toEqual(msg1.messageId); + expect(d.messages().all()[0].id()).toEqual('someMessage1'); expect(d.messages().all()[1]).toBeInstanceOf(Message); - expect(d.messages().all()[1].id()).toEqual(msg2.messageId); + expect(d.messages().all()[1].id()).toEqual('someMessage2'); }); }); diff --git a/test/models/v3/message-trait.spec.ts b/test/models/v3/message-trait.spec.ts index ad046af22..49f3b2fed 100644 --- a/test/models/v3/message-trait.spec.ts +++ b/test/models/v3/message-trait.spec.ts @@ -13,12 +13,6 @@ describe('MessageTrait model', function() { const d = new MessageTrait(doc, { asyncapi: {} as any, pointer: '', id: 'trait' }); expect(d.id()).toEqual('trait'); }); - - it('should reuse messageId', function() { - const doc = { messageId: '...' }; - const d = new MessageTrait(doc); - expect(d.id()).toEqual(doc.messageId); - }); }); describe('.schemaFormat()', function() { @@ -38,30 +32,16 @@ describe('MessageTrait model', function() { }); describe('.hasMessageId()', function() { - it('should return true when there is a value', function() { - const doc = { messageId: '...' }; - const d = new MessageTrait(doc); - expect(d.hasMessageId()).toEqual(true); - }); - - it('should return false when there is no value', function() { + it('should return false when there is a value', function() { const doc = {}; - const d = new MessageTrait(doc); + const d = new MessageTrait(doc, { asyncapi: {} as any, pointer: '', id: 'message' }); expect(d.hasMessageId()).toEqual(false); }); - }); - - describe('.messageId()', function() { - it('should return the value', function() { - const doc = { messageId: '...' }; - const d = new MessageTrait(doc); - expect(d.messageId()).toEqual(doc.messageId); - }); - it('should return undefined when there is no value', function() { + it('should return false when there is no value', function() { const doc = {}; const d = new MessageTrait(doc); - expect(d.messageId()).toBeUndefined(); + expect(d.hasMessageId()).toEqual(false); }); }); diff --git a/test/models/v3/message.spec.ts b/test/models/v3/message.spec.ts index 3bcca68d0..9d02b2885 100644 --- a/test/models/v3/message.spec.ts +++ b/test/models/v3/message.spec.ts @@ -18,12 +18,6 @@ describe('Message model', function() { const d = new Message(doc, { asyncapi: {} as any, pointer: '', id: 'message' }); expect(d.id()).toEqual('message'); }); - - it('should reuse messageId', function() { - const doc = { messageId: '...' }; - const d = new Message(doc); - expect(d.id()).toEqual(doc.messageId); - }); }); describe('.schemaFormat() + .hasSchemaFormat()', function() { diff --git a/test/models/v3/operation-reply.spec.ts b/test/models/v3/operation-reply.spec.ts index 140c24903..3f065d5a1 100644 --- a/test/models/v3/operation-reply.spec.ts +++ b/test/models/v3/operation-reply.spec.ts @@ -64,20 +64,20 @@ describe('OperationReply model', function() { describe('.messages()', function() { it('should return collection of messages - single message', function() { - const d = new OperationReply({ messages: { someMessage: { messageId: 'messageId' } } }); + const d = new OperationReply({ messages: { someMessage: {} } }); expect(d.messages()).toBeInstanceOf(Messages); expect(d.messages().all()).toHaveLength(1); expect(d.messages().all()[0]).toBeInstanceOf(Message); }); it('should return collection of messages - more than one messages', function() { - const d = new OperationReply({ messages: { someMessage1: { messageId: 'messageId1' }, someMessage2: { messageId: 'messageId2' } } }); + const d = new OperationReply({ messages: { someMessage1: {}, someMessage2: {} } }); expect(d.messages()).toBeInstanceOf(Messages); expect(d.messages().all()).toHaveLength(2); expect(d.messages().all()[0]).toBeInstanceOf(Message); - expect(d.messages().all()[0].messageId()).toEqual('messageId1'); + expect(d.messages().all()[0].id()).toEqual('someMessage1'); expect(d.messages().all()[1]).toBeInstanceOf(Message); - expect(d.messages().all()[1].messageId()).toEqual('messageId2'); + expect(d.messages().all()[1].id()).toEqual('someMessage2'); }); it('should return undefined if address is not present', function() { diff --git a/test/models/v3/operation.spec.ts b/test/models/v3/operation.spec.ts index 1bf852e4d..9dcd179bb 100644 --- a/test/models/v3/operation.spec.ts +++ b/test/models/v3/operation.spec.ts @@ -89,7 +89,7 @@ describe('Operation model', function() { describe('.messages()', function() { it('should return collection of messages - single message', function() { - const channel = { messages: { someMessage: { messageId: 'messageId' } } }; + const channel = { messages: { someMessage: { summary: 'summary' } } }; const d = new Operation({ action: 'send', channel }, { asyncapi: { parsed: { channels: { someChannel: channel } } } as any, pointer: '', id: 'operation' }); expect(d.messages()).toBeInstanceOf(Messages); expect(d.messages().all()).toHaveLength(1); @@ -97,23 +97,23 @@ describe('Operation model', function() { }); it('should return collection of messages - more than one messages', function() { - const channel = { messages: { someMessage1: { messageId: 'messageId1' }, someMessage2: { messageId: 'messageId2' } } }; + const channel = { messages: { someMessage1: { summary: 'summary1' }, someMessage2: { summary: 'summary2' } } }; const d = new Operation({ action: 'send', channel }, { asyncapi: { parsed: { channels: { someChannel: channel } } } as any, pointer: '', id: 'operation' }); expect(d.messages()).toBeInstanceOf(Messages); expect(d.messages().all()).toHaveLength(2); expect(d.messages().all()[0]).toBeInstanceOf(Message); - expect(d.messages().all()[0].messageId()).toEqual('messageId1'); + expect(d.messages().all()[0].summary()).toEqual('summary1'); expect(d.messages().all()[1]).toBeInstanceOf(Message); - expect(d.messages().all()[1].messageId()).toEqual('messageId2'); + expect(d.messages().all()[1].summary()).toEqual('summary2'); }); it('should return collection of messages - defined message on operation level', function() { - const channel = { messages: { someMessage1: { messageId: 'messageId1' }, someMessage2: { messageId: 'messageId2' } } }; + const channel = { messages: { someMessage1: { summary: 'summary1' }, someMessage2: { summary: 'summary2' } } }; const d = new Operation({ action: 'send', channel, messages: [channel.messages.someMessage1] }, { asyncapi: { parsed: { channels: { someChannel: channel } } } as any, pointer: '', id: 'operation' }); expect(d.messages()).toBeInstanceOf(Messages); expect(d.messages().all()).toHaveLength(1); expect(d.messages().all()[0]).toBeInstanceOf(Message); - expect(d.messages().all()[0].messageId()).toEqual('messageId1'); + expect(d.messages().all()[0].summary()).toEqual('summary1'); }); it('should return undefined when there is no value', function() { diff --git a/test/models/v3/server.spec.ts b/test/models/v3/server.spec.ts index 6289a8954..9059fac8c 100644 --- a/test/models/v3/server.spec.ts +++ b/test/models/v3/server.spec.ts @@ -168,33 +168,33 @@ describe('Server Model', function () { describe('.messages()', function() { it('should return collection of messages - one message', function() { const doc = serializeInput({}); - const d = new Server(doc, { asyncapi: { parsed: { channels: { someChannel: { messages: { someMessage: { messageId: 'messageId' } } } } } } as any, pointer: '', id: 'production' }); + const d = new Server(doc, { asyncapi: { parsed: { channels: { someChannel: { messages: { someMessage: { summary: 'summary' } } } } } } as any, pointer: '', id: 'production' }); expect(d.messages()).toBeInstanceOf(Messages); expect(d.messages().all()).toHaveLength(1); expect(d.messages().all()[0]).toBeInstanceOf(Message); - expect(d.messages().all()[0].messageId()).toEqual('messageId'); + expect(d.messages().all()[0].summary()).toEqual('summary'); }); it('should return collection of messages - more than one messages', function() { const doc = serializeInput({}); - const d = new Server(doc, { asyncapi: { parsed: { channels: { someChannel1: { messages: { someMessage1: { messageId: 'messageId1' } } }, someChannel2: { messages: { someMessage2: { messageId: 'messageId2' }, someMessage3: { messageId: 'messageId3' } } } } } } as any, pointer: '', id: 'production' }); + const d = new Server(doc, { asyncapi: { parsed: { channels: { someChannel1: { messages: { someMessage1: { summary: 'summary1' } } }, someChannel2: { messages: { someMessage2: { summary: 'summary2' }, someMessage3: { summary: 'summary3' } } } } } } as any, pointer: '', id: 'production' }); expect(d.messages()).toBeInstanceOf(Messages); expect(d.messages().all()).toHaveLength(3); expect(d.messages().all()[0]).toBeInstanceOf(Message); - expect(d.messages().all()[0].messageId()).toEqual('messageId1'); + expect(d.messages().all()[0].summary()).toEqual('summary1'); expect(d.messages().all()[1]).toBeInstanceOf(Message); - expect(d.messages().all()[1].messageId()).toEqual('messageId2'); + expect(d.messages().all()[1].summary()).toEqual('summary2'); expect(d.messages().all()[2]).toBeInstanceOf(Message); - expect(d.messages().all()[2].messageId()).toEqual('messageId3'); + expect(d.messages().all()[2].summary()).toEqual('summary3'); }); it('should return collection of messages - server available only in particular channel', function() { const doc = serializeInput({}); - const d = new Server(doc, { asyncapi: { parsed: { channels: { someChannel1: { servers: [doc], messages: { someMessage1: { messageId: 'messageId1' } } }, someChannel2: { servers: [{}], messages: { someMessage2: { messageId: 'messageId2' }, someMessage3: { messageId: 'messageId3' } } } } } } as any, pointer: '', id: 'production' }); + const d = new Server(doc, { asyncapi: { parsed: { channels: { someChannel1: { servers: [doc], messages: { someMessage1: { summary: 'summary1' } } }, someChannel2: { servers: [{}], messages: { someMessage2: { summary: 'summary2' }, someMessage3: { summary: 'summary3' } } } } } } as any, pointer: '', id: 'production' }); expect(d.messages()).toBeInstanceOf(Messages); expect(d.messages().all()).toHaveLength(1); expect(d.messages().all()[0]).toBeInstanceOf(Message); - expect(d.messages().all()[0].messageId()).toEqual('messageId1'); + expect(d.messages().all()[0].summary()).toEqual('summary1'); }); });