@@ -2,6 +2,7 @@ import { expect, fixture } from "@open-wc/testing";
22import { html } from "lit" ;
33import { restore , stub } from "sinon" ;
44
5+ import { APIController } from "./controllers/api" ;
56import { NavigateController } from "./controllers/navigate" ;
67import { NotifyController } from "./controllers/notify" ;
78import { type AppSettings } from "./utils/app" ;
@@ -46,6 +47,7 @@ const mockAppSettings: AppSettings = {
4647 salesEmail : "" ,
4748 supportEmail : "" ,
4849 localesEnabled : [ "en" , "es" ] ,
50+ numBrowsersPerInstance : 1 ,
4951} ;
5052
5153describe ( "browsertrix-app" , ( ) => {
@@ -55,6 +57,7 @@ describe("browsertrix-app", () => {
5557 window . localStorage . clear ( ) ;
5658 stub ( window . history , "pushState" ) ;
5759 stub ( NotifyController . prototype , "toast" ) ;
60+ stub ( APIController . prototype , "fetch" ) ;
5861 } ) ;
5962
6063 afterEach ( ( ) => {
@@ -84,15 +87,12 @@ describe("browsertrix-app", () => {
8487
8588 it ( "renders 404 when not in org" , async ( ) => {
8689 stub ( AuthService . prototype , "initSessionStorage" ) . returns (
87- Promise . resolve ( {
88- headers : { Authorization : "_fake_headers_" } ,
89- tokenExpiresAt : 0 ,
90- 91- } ) ,
90+ Promise . resolve ( mockAuth ) ,
9291 ) ;
9392 // @ts -expect-error checkFreshness is private
9493 stub ( AuthService . prototype , "checkFreshness" ) ;
9594
95+ AppStateService . updateAuth ( mockAuth ) ;
9696 AppStateService . updateUser (
9797 formatAPIUser ( {
9898 ...mockAPIUser ,
@@ -116,15 +116,12 @@ describe("browsertrix-app", () => {
116116 } ;
117117
118118 stub ( AuthService . prototype , "initSessionStorage" ) . returns (
119- Promise . resolve ( {
120- headers : { Authorization : "_fake_headers_" } ,
121- tokenExpiresAt : 0 ,
122- 123- } ) ,
119+ Promise . resolve ( mockAuth ) ,
124120 ) ;
125121 // @ts -expect-error checkFreshness is private
126122 stub ( AuthService . prototype , "checkFreshness" ) ;
127123
124+ AppStateService . updateAuth ( mockAuth ) ;
128125 AppStateService . updateUser (
129126 formatAPIUser ( {
130127 ...mockAPIUser ,
@@ -158,27 +155,6 @@ describe("browsertrix-app", () => {
158155 expect ( el . shadowRoot ?. querySelector ( "btrix-log-in" ) ) . to . exist ;
159156 } ) ;
160157
161- // TODO move tests to AuthService
162- it ( "sets auth state from session storage" , async ( ) => {
163- stub ( AuthService . prototype , "startFreshnessCheck" ) . callsFake ( ( ) => { } ) ;
164- stub ( window . sessionStorage , "getItem" ) . callsFake ( ( key ) => {
165- if ( key === "btrix.auth" )
166- return JSON . stringify ( {
167- headers : { Authorization : "_fake_headers_" } ,
168- tokenExpiresAt : 0 ,
169- 170- } ) ;
171- return null ;
172- } ) ;
173- const el = await fixture < App > ( "<browsertrix-app></browsertrix-app>" ) ;
174-
175- expect ( el . authService . authState ) . to . eql ( {
176- headers : { Authorization : "_fake_headers_" } ,
177- tokenExpiresAt : 0 ,
178- 179- } ) ;
180- } ) ;
181-
182158 it ( "sets user info" , async ( ) => {
183159 stub ( App . prototype , "getUserInfo" ) . callsFake ( async ( ) =>
184160 Promise . resolve ( mockAPIUser ) ,
@@ -227,6 +203,7 @@ describe("browsertrix-app", () => {
227203 slug : id ,
228204 role : 10 ,
229205 } ;
206+ AppStateService . updateAuth ( mockAuth ) ;
230207 AppStateService . updateUser (
231208 formatAPIUser ( {
232209 ...mockAPIUser ,
@@ -236,11 +213,7 @@ describe("browsertrix-app", () => {
236213 stub ( App . prototype , "getLocationPathname" ) . callsFake ( ( ) => `/orgs/${ id } ` ) ;
237214 stub ( AuthService . prototype , "startFreshnessCheck" ) . callsFake ( ( ) => { } ) ;
238215 stub ( AuthService . prototype , "initSessionStorage" ) . callsFake ( async ( ) =>
239- Promise . resolve ( {
240- headers : { Authorization : "_fake_headers_" } ,
241- tokenExpiresAt : 0 ,
242- 243- } ) ,
216+ Promise . resolve ( mockAuth ) ,
244217 ) ;
245218
246219 const el = await fixture < App > ( "<browsertrix-app></browsertrix-app>" ) ;
0 commit comments