@@ -114,27 +114,15 @@ func TestFormatSchema(t *testing.T) {
114114 Channel : messageflow.Channel {
115115 Name : "user.info.request" ,
116116 Message : messageflow.Message {
117- Name : "UserInfoRequest" ,
118- Payload : `{
119- "user_id": "string[uuid]"
120- }` ,
117+ Name : "UserInfoRequest" ,
118+ Payload : `{"user_id": "string[uuid]"}` ,
121119 },
122120 },
123121 Reply : & messageflow.Channel {
124122 Name : "user.info.request" ,
125123 Message : messageflow.Message {
126- Name : "UserInfoReply" ,
127- Payload : `{
128- "email": "string[email]",
129- "error": {
130- "code": "string",
131- "message": "string"
132- },
133- "language": "string",
134- "name": "string",
135- "timezone": "string",
136- "user_id": "string[uuid]"
137- }` ,
124+ Name : "UserInfoReply" ,
125+ Payload : `{"email": "string[email]", "name": "string"}` ,
138126 },
139127 },
140128 },
@@ -143,20 +131,8 @@ func TestFormatSchema(t *testing.T) {
143131 Channel : messageflow.Channel {
144132 Name : "notification.analytics" ,
145133 Message : messageflow.Message {
146- Name : "AnalyticsEvent" ,
147- Payload : `{
148- "event_id": "string[uuid]",
149- "event_type": "string[enum:notification_sent,notification_opened,notification_clicked]",
150- "metadata": {
151- "environment": "string[enum:development,staging,production]",
152- "platform": "string[enum:ios,android,web]",
153- "source": "string[enum:mobile,web,api]",
154- "version": "string"
155- },
156- "notification_id": "string[uuid]",
157- "timestamp": "string[date-time]",
158- "user_id": "string[uuid]"
159- }` ,
134+ Name : "AnalyticsEvent" ,
135+ Payload : `{"event_type": "string", "user_id": "string[uuid]"}` ,
160136 },
161137 },
162138 },
@@ -285,3 +261,120 @@ func TestFormatSchemaChannelServicesWithOmitPayloads(t *testing.T) {
285261 assert .Contains (t , actualOmittedStr , "Notification Service" )
286262 assert .Contains (t , actualOmittedStr , "User Service" )
287263}
264+
265+ func TestFormatSchemaServiceServices (t * testing.T ) {
266+ t .Parallel ()
267+
268+ schema := messageflow.Schema {
269+ Services : []messageflow.Service {
270+ {
271+ Name : "Notification Service" ,
272+ Description : "Handles notification operations" ,
273+ Operation : []messageflow.Operation {
274+ {
275+ Action : messageflow .ActionReceive ,
276+ Channel : messageflow.Channel {
277+ Name : "notification.preferences.get" ,
278+ Message : messageflow.Message {
279+ Name : "PreferencesRequest" ,
280+ Payload : `{"user_id": "string[uuid]"}` ,
281+ },
282+ },
283+ Reply : & messageflow.Channel {
284+ Name : "notification.preferences.get" ,
285+ Message : messageflow.Message {
286+ Name : "PreferencesReply" ,
287+ Payload : `{"preferences": {"email_enabled": "boolean"}}` ,
288+ },
289+ },
290+ },
291+ {
292+ Action : messageflow .ActionSend ,
293+ Channel : messageflow.Channel {
294+ Name : "user.info.request" ,
295+ Message : messageflow.Message {
296+ Name : "UserInfoRequest" ,
297+ Payload : `{"user_id": "string[uuid]"}` ,
298+ },
299+ },
300+ Reply : & messageflow.Channel {
301+ Name : "user.info.request" ,
302+ Message : messageflow.Message {
303+ Name : "UserInfoReply" ,
304+ Payload : `{"email": "string[email]", "name": "string"}` ,
305+ },
306+ },
307+ },
308+ {
309+ Action : messageflow .ActionSend ,
310+ Channel : messageflow.Channel {
311+ Name : "notification.analytics" ,
312+ Message : messageflow.Message {
313+ Name : "AnalyticsEvent" ,
314+ Payload : `{"event_type": "string", "user_id": "string[uuid]"}` ,
315+ },
316+ },
317+ },
318+ },
319+ },
320+ {
321+ Name : "User Service" ,
322+ Description : "Manages user information" ,
323+ Operation : []messageflow.Operation {
324+ {
325+ Action : messageflow .ActionReceive ,
326+ Channel : messageflow.Channel {
327+ Name : "user.info.request" ,
328+ Message : messageflow.Message {
329+ Name : "UserInfoRequest" ,
330+ Payload : `{"user_id": "string[uuid]"}` ,
331+ },
332+ },
333+ Reply : & messageflow.Channel {
334+ Name : "user.info.request" ,
335+ Message : messageflow.Message {
336+ Name : "UserInfoReply" ,
337+ Payload : `{"email": "string[email]", "name": "string"}` ,
338+ },
339+ },
340+ },
341+ },
342+ },
343+ {
344+ Name : "Analytics Service" ,
345+ Description : "Tracks analytics events" ,
346+ Operation : []messageflow.Operation {
347+ {
348+ Action : messageflow .ActionReceive ,
349+ Channel : messageflow.Channel {
350+ Name : "notification.analytics" ,
351+ Message : messageflow.Message {
352+ Name : "AnalyticsEvent" ,
353+ Payload : `{"event_type": "string", "user_id": "string[uuid]"}` ,
354+ },
355+ },
356+ },
357+ },
358+ },
359+ },
360+ }
361+
362+ ctx := context .Background ()
363+
364+ target , err := NewTarget ()
365+ require .NoError (t , err )
366+
367+ actual , err := target .FormatSchema (ctx , schema , messageflow.FormatOptions {
368+ Mode : messageflow .FormatModeServiceServices ,
369+ Service : "Notification Service" ,
370+ })
371+ require .NoError (t , err )
372+
373+ actualStr := string (actual .Data )
374+ assert .Contains (t , actualStr , "Notification Service" )
375+ assert .Contains (t , actualStr , "User Service" )
376+ assert .Contains (t , actualStr , "notification.preferences.get" )
377+ assert .Contains (t , actualStr , "user.info.request" )
378+ assert .Contains (t , actualStr , "notification.analytics" )
379+ assert .Contains (t , actualStr , "Analytics Service" )
380+ }
0 commit comments