@@ -60,36 +60,105 @@ describe("client", () => {
6060 }
6161 }
6262 } ) ;
63+ } ) ;
6364
64- it ( "uses input arguments when constructing the web api client" , async ( ) => {
65- const spy = sinon . spy ( mocks . webapi , "WebClient" ) ;
65+ describe ( "api" , async ( ) => {
66+ it ( "uses arguments to send to a slack api method" , async ( ) => {
67+ const apis = sinon . stub ( ) . resolves ( { ok : true } ) ;
68+ const constructors = sinon
69+ . stub ( mocks . webapi , "WebClient" )
70+ . returns ( { apiCall : apis } ) ;
6671 /**
6772 * @type {Config }
6873 */
6974 const config = {
7075 content : {
71- values : { } ,
76+ values : {
77+ channel : "CHANNELHERE" ,
78+ timestamp : "1234567890.000000" ,
79+ } ,
7280 } ,
7381 core : core ,
7482 logger : new Logger ( core ) . logger ,
7583 inputs : {
76- api : "http://localhost:8080/api" ,
7784 method : "pins.add" ,
78- retries : "10" ,
7985 token : "xoxb-example-002" ,
8086 } ,
8187 webapi : mocks . webapi ,
8288 } ;
8389 await new Client ( ) . post ( config ) ;
84- assert . isTrue ( spy . calledWithNew ( ) ) ;
90+ assert . isTrue ( constructors . calledWithNew ( ) ) ;
8591 assert . isTrue (
86- spy . calledWith ( "xoxb-example-002" , {
92+ constructors . calledWith ( "xoxb-example-002" , {
8793 agent : undefined ,
94+ allowAbsoluteUrls : false ,
95+ logger : config . logger ,
96+ retryConfig : webapi . retryPolicies . fiveRetriesInFiveMinutes ,
97+ slackApiUrl : undefined ,
98+ } ) ,
99+ ) ;
100+ assert . isTrue ( apis . calledOnce ) ;
101+ assert . isTrue (
102+ apis . calledWith ( "pins.add" , {
103+ channel : "CHANNELHERE" ,
104+ timestamp : "1234567890.000000" ,
105+ } ) ,
106+ ) ;
107+ assert . isTrue ( config . core . setOutput . calledWith ( "ok" , true ) ) ;
108+ } ) ;
109+
110+ it ( "uses arguments to send to a custom api method" , async ( ) => {
111+ const apis = sinon . stub ( ) . resolves ( { done : true , response : "Infinite" } ) ;
112+ const constructors = sinon
113+ . stub ( mocks . webapi , "WebClient" )
114+ . returns ( { apiCall : apis } ) ;
115+ /**
116+ * @type {Config }
117+ */
118+ const config = {
119+ content : {
120+ values : {
121+ model : "llama3.2" ,
122+ prompt : "How many sides does a circle have?" ,
123+ stream : false ,
124+ } ,
125+ } ,
126+ core : core ,
127+ logger : new Logger ( core ) . logger ,
128+ inputs : {
129+ api : "http://localhost:11434/api/" ,
130+ method : "generate" ,
131+ retries : "10" ,
132+ token : "ollamapassword" ,
133+ } ,
134+ webapi : mocks . webapi ,
135+ } ;
136+ await new Client ( ) . post ( config ) ;
137+ assert . isTrue ( constructors . calledWithNew ( ) ) ;
138+ assert . isTrue (
139+ constructors . calledWith ( "ollamapassword" , {
140+ agent : undefined ,
141+ allowAbsoluteUrls : false ,
88142 logger : config . logger ,
89143 retryConfig : webapi . retryPolicies . tenRetriesInAboutThirtyMinutes ,
90- slackApiUrl : "http://localhost:8080/api" ,
144+ slackApiUrl : "http://localhost:11434/api/" ,
145+ } ) ,
146+ ) ;
147+ assert . isTrue ( apis . calledOnce ) ;
148+ assert . isTrue (
149+ apis . calledWith ( "generate" , {
150+ model : "llama3.2" ,
151+ prompt : "How many sides does a circle have?" ,
152+ stream : false ,
91153 } ) ,
92154 ) ;
155+ assert . isTrue ( config . core . setOutput . calledWith ( "ok" , undefined ) ) ;
156+ assert . isTrue (
157+ config . core . setOutput . calledWith (
158+ "response" ,
159+ JSON . stringify ( { done : true , response : "Infinite" } ) ,
160+ ) ,
161+ ) ;
93162 } ) ;
94163 } ) ;
95164
0 commit comments