Skip to content

Commit 6f15817

Browse files
committed
fix test
1 parent 5a2e630 commit 6f15817

File tree

2 files changed

+127
-39
lines changed

2 files changed

+127
-39
lines changed

test/codegen/generators/typescript/__snapshots__/channels.spec.ts.snap

Lines changed: 122 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,28 @@ import * as Nats from 'nats';
77
export const Protocols = {
88
nats: {
99
/**
10+
* NATS publish operation for \`user.signedup\`
11+
*
12+
* @param message to publish
13+
* @param nc the NATS client to publish from
14+
* @param codec the serialization codec to use while transmitting the message
15+
* @param options to use while publishing the message
16+
*/
17+
publishToUserSignedup: (
18+
message: MessageTypeModule.MessageType, nc: Nats.NatsConnection, codec: any = Nats.JSONCodec(), options?: Nats.PublishOptions
19+
): Promise<void> => {
20+
return new Promise<void>(async (resolve, reject) => {
21+
try {
22+
let dataToSend: any = MessageTypeModule.marshal(message);
23+
dataToSend = codec.encode(dataToSend);
24+
nc.publish('user.signedup', dataToSend, options);
25+
resolve();
26+
} catch (e: any) {
27+
reject(e);
28+
}
29+
});
30+
},
31+
/**
1032
* Callback for when receiving messages
1133
*
1234
* @callback subscribeToUserSignedupCallback
@@ -116,6 +138,28 @@ onDataCallback(undefined, MessageTypeModule.unmarshal(receivedData), msg);
116138
reject(e);
117139
}
118140
});
141+
},
142+
/**
143+
* JetStream publish operation for \`user.signedup\`
144+
*
145+
* @param message to publish over jetstream
146+
* @param js the JetStream client to publish from
147+
* @param codec the serialization codec to use while transmitting the message
148+
* @param options to use while publishing the message
149+
*/
150+
jetStreamPublishToUserSignedup: (
151+
message: MessageTypeModule.MessageType, js: Nats.JetStreamClient, codec: any = Nats.JSONCodec(), options: Partial<Nats.JetStreamPublishOptions> = {}
152+
): Promise<void> => {
153+
return new Promise<void>(async (resolve, reject) => {
154+
try {
155+
let dataToSend: any = MessageTypeModule.marshal(message);
156+
dataToSend = codec.encode(dataToSend);
157+
await js.publish('user.signedup', dataToSend, options);
158+
resolve();
159+
} catch (e: any) {
160+
reject(e);
161+
}
162+
});
119163
}
120164
}};"
121165
`;
@@ -126,6 +170,28 @@ import * as Nats from 'nats';
126170
export const Protocols = {
127171
nats: {
128172
/**
173+
* NATS publish operation for \`user.signedup\`
174+
*
175+
* @param message to publish
176+
* @param nc the NATS client to publish from
177+
* @param codec the serialization codec to use while transmitting the message
178+
* @param options to use while publishing the message
179+
*/
180+
publishToUserSignedup: (
181+
message: MessageTypeModule.MessageType, nc: Nats.NatsConnection, codec: any = Nats.JSONCodec(), options?: Nats.PublishOptions
182+
): Promise<void> => {
183+
return new Promise<void>(async (resolve, reject) => {
184+
try {
185+
let dataToSend: any = MessageTypeModule.marshal(message);
186+
dataToSend = codec.encode(dataToSend);
187+
nc.publish('user.signedup', dataToSend, options);
188+
resolve();
189+
} catch (e: any) {
190+
reject(e);
191+
}
192+
});
193+
},
194+
/**
129195
* Callback for when receiving messages
130196
*
131197
* @callback subscribeToUserSignedupCallback
@@ -235,6 +301,28 @@ onDataCallback(undefined, MessageTypeModule.unmarshal(receivedData), msg);
235301
reject(e);
236302
}
237303
});
304+
},
305+
/**
306+
* JetStream publish operation for \`user.signedup\`
307+
*
308+
* @param message to publish over jetstream
309+
* @param js the JetStream client to publish from
310+
* @param codec the serialization codec to use while transmitting the message
311+
* @param options to use while publishing the message
312+
*/
313+
jetStreamPublishToUserSignedup: (
314+
message: MessageTypeModule.MessageType, js: Nats.JetStreamClient, codec: any = Nats.JSONCodec(), options: Partial<Nats.JetStreamPublishOptions> = {}
315+
): Promise<void> => {
316+
return new Promise<void>(async (resolve, reject) => {
317+
try {
318+
let dataToSend: any = MessageTypeModule.marshal(message);
319+
dataToSend = codec.encode(dataToSend);
320+
await js.publish('user.signedup', dataToSend, options);
321+
resolve();
322+
} catch (e: any) {
323+
reject(e);
324+
}
325+
});
238326
}
239327
}};"
240328
`;
@@ -245,6 +333,28 @@ import * as Nats from 'nats';
245333
export const Protocols = {
246334
nats: {
247335
/**
336+
* NATS publish operation for \`ping\`
337+
*
338+
* @param message to publish
339+
* @param nc the NATS client to publish from
340+
* @param codec the serialization codec to use while transmitting the message
341+
* @param options to use while publishing the message
342+
*/
343+
publishToPing: (
344+
message: MessageTypeModule.MessageType, nc: Nats.NatsConnection, codec: any = Nats.JSONCodec(), options?: Nats.PublishOptions
345+
): Promise<void> => {
346+
return new Promise<void>(async (resolve, reject) => {
347+
try {
348+
let dataToSend: any = MessageTypeModule.marshal(message);
349+
dataToSend = codec.encode(dataToSend);
350+
nc.publish('ping', dataToSend, options);
351+
resolve();
352+
} catch (e: any) {
353+
reject(e);
354+
}
355+
});
356+
},
357+
/**
248358
* Callback for when receiving messages
249359
*
250360
* @callback subscribeToPingCallback
@@ -356,47 +466,22 @@ onDataCallback(undefined, MessageTypeModule.unmarshal(receivedData), msg);
356466
});
357467
},
358468
/**
359-
* Callback for when receiving the request
360-
*
361-
* @callback replyToPingCallback
362-
* @param err if any error occurred this will be sat
363-
* @param requestMessage that was received from the request
364-
*/
365-
366-
/**
367-
* Reply for \`ping\`
469+
* JetStream publish operation for \`ping\`
368470
*
369-
* @param {replyToPingCallback} onDataCallback to call when the request is received
370-
* @param nc the nats client to setup the reply for
371-
* @param codec the serialization codec to use when receiving and transmitting reply
372-
* @param options when setting up the reply
471+
* @param message to publish over jetstream
472+
* @param js the JetStream client to publish from
473+
* @param codec the serialization codec to use while transmitting the message
474+
* @param options to use while publishing the message
373475
*/
374-
replyToPing: (
375-
onDataCallback: (err?: Error, requestMessage?: MessageTypeModule.MessageType) => MessageTypeModule | Promise<MessageTypeModule>,
376-
nc: Nats.NatsConnection,
377-
codec: any = Nats.JSONCodec(),
378-
options?: Nats.SubscriptionOptions
379-
): Promise<Nats.Subscription> => {
380-
return new Promise(async (resolve, reject) => {
476+
jetStreamPublishToPing: (
477+
message: MessageTypeModule.MessageType, js: Nats.JetStreamClient, codec: any = Nats.JSONCodec(), options: Partial<Nats.JetStreamPublishOptions> = {}
478+
): Promise<void> => {
479+
return new Promise<void>(async (resolve, reject) => {
381480
try {
382-
let subscription = nc.subscribe('ping', options);
383-
(async () => {
384-
for await (const msg of subscription) {
385-
386-
387-
let receivedData : any = codec.decode(msg.data);
388-
const replyMessage = await onDataCallback(undefined, MessageTypeModule.unmarshal(receivedData) );
389-
390-
if (msg.reply) {
391-
let dataToSend : any = replyMessage.marshal();
481+
let dataToSend: any = MessageTypeModule.marshal(message);
392482
dataToSend = codec.encode(dataToSend);
393-
msg.respond(dataToSend);
394-
} else {
395-
onDataCallback(new Error('Expected request to need a reply, did not..'))
396-
}
397-
}
398-
})();
399-
resolve(subscription);
483+
await js.publish('ping', dataToSend, options);
484+
resolve();
400485
} catch (e: any) {
401486
reject(e);
402487
}

test/codegen/generators/typescript/channels.spec.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@ describe('channels', () => {
3838
...defaultTypeScriptChannelsGenerator,
3939
outputPath: path.resolve(__dirname, './output'),
4040
protocols: ['nats'],
41-
id: 'test'
41+
id: 'test',
42+
asyncapiGenerateForOperations: false,
4243
},
4344
inputType: 'asyncapi',
4445
asyncapiDocument: parsedAsyncAPIDocument,
@@ -77,7 +78,8 @@ describe('channels', () => {
7778
...defaultTypeScriptChannelsGenerator,
7879
outputPath: path.resolve(__dirname, './output'),
7980
protocols: ['nats'],
80-
id: 'test'
81+
id: 'test',
82+
asyncapiGenerateForOperations: false
8183
},
8284
inputType: 'asyncapi',
8385
asyncapiDocument: parsedAsyncAPIDocument,
@@ -114,6 +116,7 @@ describe('channels', () => {
114116
outputPath: path.resolve(__dirname, './output'),
115117
protocols: ['nats'],
116118
id: 'test',
119+
asyncapiGenerateForOperations: false
117120
},
118121
inputType: 'asyncapi',
119122
asyncapiDocument: parsedAsyncAPIDocument,

0 commit comments

Comments
 (0)