11import { jest } from "@jest/globals" ;
2+ import { ReplicateError } from "./errors.js" ;
23import { PredictionStatus } from "./Prediction.js" ;
34import ReplicateClient from "./ReplicateClient.js" ;
45
@@ -10,6 +11,46 @@ beforeEach(() => {
1011 client = new ReplicateClient ( { } ) ;
1112} ) ;
1213
14+ describe ( "baseURL" , ( ) => {
15+ it ( "is baseURL provided to constructor" , ( ) => {
16+ const client = new ReplicateClient ( {
17+ baseURL : "http://test.host" ,
18+ } ) ;
19+
20+ expect ( client . baseURL ) . toEqual ( "http://test.host" ) ;
21+ } ) ;
22+
23+ it ( "defaults to https://api.replicate.com" , ( ) => {
24+ const client = new ReplicateClient ( { } ) ;
25+
26+ expect ( client . baseURL ) . toEqual ( "https://api.replicate.com" ) ;
27+ } ) ;
28+ } ) ;
29+
30+ describe ( "token" , ( ) => {
31+ it ( "is token provided to constructor" , ( ) => {
32+ const client = new ReplicateClient ( {
33+ token : "test-token-from-constructor" ,
34+ } ) ;
35+
36+ expect ( client . token ) . toEqual ( "test-token-from-constructor" ) ;
37+ } ) ;
38+
39+ it ( "defaults to REPLICATE_API_TOKEN env var" , ( ) => {
40+ const client = new ReplicateClient ( { } ) ;
41+
42+ expect ( client . token ) . toEqual ( "test-token-from-env" ) ;
43+ } ) ;
44+ } ) ;
45+
46+ describe ( "constructor()" , ( ) => {
47+ it ( "throws when no token is provided or set in env" , ( ) => {
48+ delete process . env . REPLICATE_API_TOKEN ;
49+
50+ expect ( ( ) => new ReplicateClient ( { } ) ) . toThrowError ( ReplicateError ) ;
51+ } ) ;
52+ } ) ;
53+
1354describe ( "predict()" , ( ) => {
1455 it ( "makes request to create prediction" , async ( ) => {
1556 jest
0 commit comments