Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions packages/cloud/src/CloudService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,11 @@ export class CloudService {
this.authService.on("logged-out", this.authListener)
this.authService.on("user-info", this.authListener)

this.settingsService = new SettingsService(this.context, this.authService, () =>
this.callbacks.stateChanged?.(),
this.settingsService = new SettingsService(
this.context,
this.authService,
() => this.callbacks.stateChanged?.(),
this.log,
)
this.settingsService.initialize()

Expand Down
21 changes: 16 additions & 5 deletions packages/cloud/src/SettingsService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,17 @@ export class SettingsService {
private authService: AuthService
private settings: OrganizationSettings | undefined = undefined
private timer: RefreshTimer

constructor(context: vscode.ExtensionContext, authService: AuthService, callback: () => void) {
private log: (...args: unknown[]) => void

constructor(
context: vscode.ExtensionContext,
authService: AuthService,
callback: () => void,
log?: (...args: unknown[]) => void,
) {
this.context = context
this.authService = authService
this.log = log || console.log

this.timer = new RefreshTimer({
callback: async () => {
Expand Down Expand Up @@ -70,15 +77,19 @@ export class SettingsService {
})

if (!response.ok) {
console.error(`Failed to fetch organization settings: ${response.status} ${response.statusText}`)
this.log(
"[cloud-settings] Failed to fetch organization settings:",
response.status,
response.statusText,
)
return false
}

const data = await response.json()
const result = organizationSettingsSchema.safeParse(data)

if (!result.success) {
console.error("Invalid organization settings format:", result.error)
this.log("[cloud-settings] Invalid organization settings format:", result.error)
return false
}

Expand All @@ -92,7 +103,7 @@ export class SettingsService {

return true
} catch (error) {
console.error("Error fetching organization settings:", error)
this.log("[cloud-settings] Error fetching organization settings:", error)
return false
}
}
Expand Down
7 changes: 6 additions & 1 deletion packages/cloud/src/__tests__/CloudService.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,12 @@ describe("CloudService", () => {

expect(cloudService).toBeInstanceOf(CloudService)
expect(AuthService).toHaveBeenCalledWith(mockContext, expect.any(Function))
expect(SettingsService).toHaveBeenCalledWith(mockContext, mockAuthService, expect.any(Function))
expect(SettingsService).toHaveBeenCalledWith(
mockContext,
mockAuthService,
expect.any(Function),
expect.any(Function),
)
})

it("should throw error if instance already exists", async () => {
Expand Down
Loading