@@ -27,17 +27,30 @@ vi.mock("./runtime.js", () => ({
2727
2828import { startGoogleChatMonitor } from "./monitor.js" ;
2929
30+ const configuredAccount = {
31+ accountId : "default" ,
32+ enabled : true ,
33+ credentialSource : "config" ,
34+ config : {
35+ audienceType : "project-number" ,
36+ audience : "1234567890" ,
37+ } ,
38+ } ;
39+
3040describe ( "Google Chat monitor lifecycle" , ( ) => {
3141 beforeEach ( ( ) => {
3242 vi . clearAllMocks ( ) ;
3343 mocks . registerTarget . mockReturnValue ( vi . fn ( ) ) ;
3444 } ) ;
3545
36- it ( "publishes ready after the webhook target is registered" , async ( ) => {
46+ it . each ( [
47+ { audienceType : "app-url" , audience : "https://chat.example.test/googlechat" } ,
48+ { audienceType : "project-number" , audience : "1234567890" } ,
49+ ] ) ( "publishes ready after the $audienceType webhook target is registered" , async ( config ) => {
3750 const statusSink = vi . fn ( ) ;
3851
3952 const stop = await startGoogleChatMonitor ( {
40- account : { accountId : "default" , enabled : true , credentialSource : " config" , config : { } } ,
53+ account : { ... configuredAccount , config } ,
4154 config : { } ,
4255 runtime : { } ,
4356 abortSignal : new AbortController ( ) . signal ,
@@ -46,6 +59,7 @@ describe("Google Chat monitor lifecycle", () => {
4659 } as never ) ;
4760
4861 expect ( mocks . registerTarget ) . toHaveBeenCalledOnce ( ) ;
62+ expect ( mocks . registerTarget ) . toHaveBeenCalledWith ( expect . objectContaining ( config ) ) ;
4963 expect ( statusSink ) . toHaveBeenCalledWith ( {
5064 running : true ,
5165 connected : true ,
@@ -57,6 +71,54 @@ describe("Google Chat monitor lifecycle", () => {
5771 await stop ( ) ;
5872 } ) ;
5973
74+ it . each ( [
75+ { description : "both audience settings are missing" , config : { } } ,
76+ { description : "the audience is missing" , config : { audienceType : "app-url" } } ,
77+ {
78+ description : "the audience is blank" ,
79+ config : { audienceType : "app-url" , audience : " " } ,
80+ } ,
81+ {
82+ description : "the audience type is missing" ,
83+ config : { audience : "https://chat.example.test/googlechat" } ,
84+ } ,
85+ {
86+ description : "the audience type is unsupported" ,
87+ config : {
88+ audienceType : "unsupported" ,
89+ audience : "https://chat.example.test/googlechat" ,
90+ } ,
91+ } ,
92+ ] ) ( "blocks startup when $description" , async ( { config } ) => {
93+ const statusSink = vi . fn ( ) ;
94+ const runtime = { error : vi . fn ( ) } ;
95+
96+ const stop = await startGoogleChatMonitor ( {
97+ account : { ...configuredAccount , config } ,
98+ config : { } ,
99+ runtime,
100+ abortSignal : new AbortController ( ) . signal ,
101+ webhookPath : "/googlechat" ,
102+ statusSink,
103+ } as never ) ;
104+
105+ expect ( mocks . ingressStart ) . not . toHaveBeenCalled ( ) ;
106+ expect ( mocks . registerTarget ) . not . toHaveBeenCalled ( ) ;
107+ expect ( statusSink ) . toHaveBeenCalledWith ( {
108+ lifecycle : "blocked" ,
109+ terminalDisconnect : true ,
110+ running : true ,
111+ connected : false ,
112+ webhookPath : undefined ,
113+ lastError : expect . stringContaining ( "channels.googlechat.audienceType" ) ,
114+ } ) ;
115+ expect ( runtime . error ) . toHaveBeenCalledWith (
116+ expect . stringContaining ( "channels.googlechat.audience" ) ,
117+ ) ;
118+ await expect ( stop ( ) ) . resolves . toBeUndefined ( ) ;
119+ expect ( mocks . ingressStop ) . not . toHaveBeenCalled ( ) ;
120+ } ) ;
121+
60122 it ( "stops ingress and rejects startup when the webhook route cannot bind" , async ( ) => {
61123 const statusSink = vi . fn ( ) ;
62124 mocks . registerTarget . mockImplementationOnce ( ( ) => {
@@ -65,7 +127,7 @@ describe("Google Chat monitor lifecycle", () => {
65127
66128 await expect (
67129 startGoogleChatMonitor ( {
68- account : { accountId : "default" , enabled : true , credentialSource : "config" , config : { } } ,
130+ account : configuredAccount ,
69131 config : { } ,
70132 runtime : { } ,
71133 abortSignal : new AbortController ( ) . signal ,
0 commit comments