11import { assert , it } from "@effect/vitest" ;
22import * as Effect from "effect/Effect" ;
33import * as Fiber from "effect/Fiber" ;
4+ import * as Option from "effect/Option" ;
45import * as Redacted from "effect/Redacted" ;
56import * as Stream from "effect/Stream" ;
67import * as TestClock from "effect/testing/TestClock" ;
@@ -14,7 +15,7 @@ const target = { host: "github.com", repository: "pingdotgg/t3code", number: 15
1415const sse = ( ...frames : ReadonlyArray < readonly [ string , string ] > ) =>
1516 frames . map ( ( [ event , data ] ) => `event: ${ event } \ndata: ${ data } \n\n` ) . join ( "" ) ;
1617
17- function fakeRest ( subscribe : ( count : number ) => Effect . Effect < string > ) {
18+ function fakeRest ( subscribe : ( count : number ) => Effect . Effect < string > , signedIn = true ) {
1819 const posts : Array < unknown > = [ ] ;
1920 const deletes : Array < string > = [ ] ;
2021 const rest = GitHubRest . GitHubRest . of ( {
@@ -42,7 +43,16 @@ function fakeRest(subscribe: (count: number) => Effect.Effect<string>) {
4243 ? { token : Redacted . make ( "user-token" ) , fingerprint : "user" , source : "gh" as const }
4344 : { token : Redacted . make ( "app-token" ) , fingerprint : "app" , source : "app" as const } ,
4445 ) ,
45- appCredential : ( ) => Effect . succeedNone ,
46+ appCredential : ( ) =>
47+ Effect . succeed (
48+ signedIn
49+ ? Option . some ( {
50+ token : Redacted . make ( "app-token" ) ,
51+ fingerprint : "app" ,
52+ source : "app" as const ,
53+ } )
54+ : Option . none ( ) ,
55+ ) ,
4656 } ) ;
4757 return { rest, posts, deletes } ;
4858}
@@ -103,3 +113,22 @@ it.effect("follows a pull request across a refused app token, reconnects, and re
103113 assert . deepEqual ( deletes , [ "event-subscriptions/1" , "event-subscriptions/2" ] ) ;
104114 } ) ,
105115) ;
116+
117+ it . effect ( "leaves users without the app sign-in, and other hosts, to polling" , ( ) =>
118+ Effect . gen ( function * ( ) {
119+ const httpClient = HttpClient . make ( ( ) => Effect . die ( "no stream without a subscription" ) ) ;
120+ const signedOut = fakeRest ( subscription , false ) ;
121+ assert . equal (
122+ yield * Stream . runCount ( GitHubPullRequestEvents . make ( signedOut . rest , httpClient ) ( target ) ) ,
123+ 0 ,
124+ ) ;
125+
126+ const signedIn = fakeRest ( subscription ) ;
127+ const enterprise = { ...target , host : "ghe.example.com" } ;
128+ assert . equal (
129+ yield * Stream . runCount ( GitHubPullRequestEvents . make ( signedIn . rest , httpClient ) ( enterprise ) ) ,
130+ 0 ,
131+ ) ;
132+ assert . equal ( signedOut . posts . length + signedIn . posts . length , 0 ) ;
133+ } ) ,
134+ ) ;
0 commit comments