forked from asyncapi/parser-js
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: add filters to some collections (asyncapi#592)
- Loading branch information
1 parent
0c70963
commit 3656738
Showing
14 changed files
with
243 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,7 @@ | ||
import type { Collection } from "./collection"; | ||
import type { ChannelInterface } from "./channel"; | ||
|
||
export interface ChannelsInterface extends Collection<ChannelInterface> {} | ||
export interface ChannelsInterface extends Collection<ChannelInterface> { | ||
filterBySend(): ChannelInterface[]; | ||
filterByReceive(): ChannelInterface[]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,7 @@ | ||
import type { Collection } from "./collection"; | ||
import type { MessageInterface } from "./message"; | ||
|
||
export interface MessagesInterface extends Collection<MessageInterface> {} | ||
export interface MessagesInterface extends Collection<MessageInterface> { | ||
filterBySend(): MessageInterface[]; | ||
filterByReceive(): MessageInterface[]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,7 @@ | ||
import type { Collection } from "./collection"; | ||
import type { OperationInterface } from "./operation"; | ||
|
||
export interface OperationsInterface extends Collection<OperationInterface> {} | ||
export interface OperationsInterface extends Collection<OperationInterface> { | ||
filterBySend(): OperationInterface[]; | ||
filterByReceive(): OperationInterface[]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,7 @@ | ||
import type { Collection } from "./collection"; | ||
import type { ServerInterface } from "./server"; | ||
|
||
export interface ServersInterface extends Collection<ServerInterface> {} | ||
export interface ServersInterface extends Collection<ServerInterface> { | ||
filterBySend(): ServerInterface[]; | ||
filterByReceive(): ServerInterface[]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,45 +1,78 @@ | ||
import { Messages } from '../../../src/models/v2/messages'; | ||
import { Message } from '../../../src/models/v2/message'; | ||
|
||
const message = { | ||
messageId: 'test', | ||
}; | ||
const messageItem = new Message(message, { asyncapi: {} as any, pointer: '', id: 'test' }); | ||
const messages = { | ||
test1: { messageId: 'test1' }, | ||
test2: { messageId: 'test2' }, | ||
test3: { messageId: 'test3' }, | ||
test4: { messageId: 'test4' }, | ||
} | ||
|
||
const messageItems = [ | ||
new Message(messages.test1, { asyncapi: { parsed: { channels: { test1: { publish: { operationId: "test1", message: messages.test1 } } } } } as any, pointer: '', id: 'test1' }), | ||
new Message(messages.test2, { asyncapi: { parsed: { channels: { test2: { publish: { operationId: "test2", message: messages.test2 } } } } } as any, pointer: '', id: 'test2' }), | ||
new Message(messages.test3, { asyncapi: { parsed: { channels: { test3: { subscribe: { operationId: "test3", message: messages.test3 } } } } } as any, pointer: '', id: 'test3' }), | ||
new Message(messages.test4, { asyncapi: { parsed: { channels: { test4: { subscribe: { operationId: "test4", message: messages.test4 } } } } } as any, pointer: '', id: 'test4' }), | ||
]; | ||
|
||
describe('Messages model', function () { | ||
describe('.isEmpty()', function () { | ||
it('should return true if collection is empty', function () { | ||
const servers = new Messages([]); | ||
expect(servers.isEmpty()).toEqual(true); | ||
const messages = new Messages([]); | ||
expect(messages.isEmpty()).toEqual(true); | ||
}); | ||
|
||
it('should return false if collection is not empty', function () { | ||
const servers = new Messages([messageItem]); | ||
expect(servers.isEmpty()).toEqual(false); | ||
const messages = new Messages([messageItems[0]]); | ||
expect(messages.isEmpty()).toEqual(false); | ||
}); | ||
}); | ||
|
||
describe('.get(id)', function () { | ||
it('should return a specific Message if it is present', function () { | ||
const servers = new Messages([messageItem]); | ||
expect(servers.get('test')).toBeTruthy(); | ||
const messages = new Messages([messageItems[0]]); | ||
expect(messages.get('test1')).toBeTruthy(); | ||
}); | ||
|
||
it('should return undefined if specific Message is missing', function () { | ||
const servers = new Messages([]); | ||
expect(servers.get('test')).toBeUndefined(); | ||
const messages = new Messages([]); | ||
expect(messages.get('test1')).toBeUndefined(); | ||
}); | ||
}); | ||
|
||
describe('.has(id)', function () { | ||
it('should return true if the said id is available', function () { | ||
const servers = new Messages([messageItem]); | ||
expect(servers.has('test')).toEqual(true); | ||
const messages = new Messages([messageItems[0]]); | ||
expect(messages.has('test1')).toEqual(true); | ||
}) | ||
|
||
it('should return false if the Message id is missing', function () { | ||
const servers = new Messages([messageItem]); | ||
expect(servers.has('anotherId')).toEqual(false); | ||
const messages = new Messages([messageItems[0]]); | ||
expect(messages.has('anotherId')).toEqual(false); | ||
}) | ||
}) | ||
|
||
describe('.filterBySend()', function () { | ||
it('should return all messages in channels with subscribe operation', function () { | ||
const messages = new Messages(messageItems); | ||
expect(messages.filterBySend()).toEqual([messageItems[2], messageItems[3]]); | ||
}) | ||
|
||
it('should return empty if there are no messages in channels with operations with subscribe action', function () { | ||
const messages = new Messages([messageItems[0], messageItems[1]]); | ||
expect(messages.filterBySend()).toEqual([]); | ||
}) | ||
}) | ||
|
||
describe('.filterByReceive()', function () { | ||
it('should return all messages in channels with publish operation', function () { | ||
const messages = new Messages(messageItems); | ||
expect(messages.filterByReceive()).toEqual([messageItems[0], messageItems[1]]); | ||
}) | ||
|
||
it('should return empty if there are no messages in channels with operations with publish action', function () { | ||
const messages = new Messages([messageItems[2], messageItems[3]]); | ||
expect(messages.filterByReceive()).toEqual([]); | ||
}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.