Skip to content

Commit

Permalink
feat golang: fixed tests for go-asyncapi-comments example
Browse files Browse the repository at this point in the history
  • Loading branch information
Владислав Муранов committed Nov 5, 2024
1 parent 9c471ce commit b95d20f
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,26 @@

exports[`Should be able to render Go Models and should log expected output to console 1`] = `
Array [
"// this is an object
type ExampleStruct struct {
Id int \`json:\\"id,omitempty\\"\`
// this is example msg uid
MsgUid string \`json:\\"msgUid\\" binding:\\"required\\"\`
// this is example event name
EvtName string \`json:\\"evtName,omitempty\\"\`
"// Payload for updating stock information
type StockUpdatePayload struct {
ProductId string \`json:\\"productId\\" binding:\\"required\\"\`
// The updated quantity of the product
Quantity int \`json:\\"quantity,omitempty\\"\`
// Warehouse location of the product
Location string \`json:\\"location,omitempty\\"\`
}",
]
`;
exports[`Should be able to render Go Models and should log expected output to console 2`] = `
Array [
"// Payload for low stock alerts
type LowStockPayload struct {
ProductId string \`json:\\"productId\\" binding:\\"required\\"\`
// The stock level threshold
Threshold int \`json:\\"threshold\\" binding:\\"required\\"\`
// The current stock level
CurrentStock int \`json:\\"currentStock,omitempty\\"\`
}",
]
`;
3 changes: 2 additions & 1 deletion examples/generate-go-asyncapi-comments/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ describe('Should be able to render Go Models', () => {
});
test('and should log expected output to console', async () => {
await generate();
expect(spy.mock.calls.length).toEqual(1);
expect(spy.mock.calls.length).toEqual(2);
expect(spy.mock.calls[0]).toMatchSnapshot();
expect(spy.mock.calls[1]).toMatchSnapshot();
});
});
73 changes: 52 additions & 21 deletions examples/generate-go-asyncapi-comments/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ import {
GoCommonPresetOptions
} from '../../src';
import { Parser } from '@asyncapi/parser';
import { TypeScriptGenerator } from '../../src';
const generatorts = new TypeScriptGenerator();
const options: GoCommonPresetOptions = { addJsonTag: true };
const generator = new GoGenerator({
presets: [GO_DESCRIPTION_PRESET, { preset: GO_COMMON_PRESET, options }]
Expand All @@ -15,41 +13,74 @@ const generator = new GoGenerator({
const AsyncAPIDocumentText = `
asyncapi: 3.0.0
info:
title: example
version: 0.0.1
title: inventoryService
version: 2.1.0
channels:
root:
address: /
inventory:
address: /inventory
messages:
exampleRequest:
summary: example operation
updateStock:
summary: Update stock levels
payload:
title: exampleStruct
title: stockUpdatePayload
type: object
description: this is an object
description: Payload for updating stock information
required:
- msgUid
- productId
additionalProperties: false
properties:
id:
productId:
type: string
quantity:
type: integer
msgUid:
description: The updated quantity of the product
location:
type: string
description: this is example msg uid
evtName:
description: Warehouse location of the product
alerts:
address: /alerts
messages:
lowStockAlert:
summary: Low stock level alert
payload:
title: lowStockPayload
type: object
description: Payload for low stock alerts
required:
- productId
- threshold
additionalProperties: false
properties:
productId:
type: string
description: this is example event name
threshold:
type: integer
description: The stock level threshold
currentStock:
type: integer
description: The current stock level
operations:
exampleOperation:
title: This is an example operation
summary: To do something
updateInventory:
title: Update Inventory Operation
summary: Operation to update inventory stock levels
channel:
$ref: '#/channels/root'
$ref: '#/channels/inventory'
action: send
messages:
- $ref: '#/channels/root/messages/exampleRequest'
- $ref: '#/channels/inventory/messages/updateStock'
notifyLowStock:
title: Notify Low Stock Operation
summary: Operation to notify when stock is low
channel:
$ref: '#/channels/alerts'
action: receive
messages:
- $ref: '#/channels/alerts/messages/lowStockAlert'
`;



export async function generate(): Promise<void> {
const parser = new Parser();
const { document } = await parser.parse(AsyncAPIDocumentText);
Expand Down

0 comments on commit b95d20f

Please sign in to comment.