Skip to content

Commit cec4c35

Browse files
Add notification and test
1 parent 180014e commit cec4c35

2 files changed

Lines changed: 56 additions & 0 deletions

File tree

src/cloud/auth.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,11 @@ export class CloudAuthenticationProvider
247247

248248
const sessions = await this.getSessions()
249249
const session = sessions[0]
250+
251+
window.showInformationMessage(
252+
`Signed in to FastAPI Cloud as ${session.account.label}`,
253+
)
254+
250255
this._onDidChangeSessions.fire({
251256
added: [session],
252257
removed: [],

src/test/cloud/auth.test.ts

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -387,6 +387,57 @@ suite("cloud/auth", () => {
387387
await provider.dispose()
388388
})
389389

390+
test("shows notification after device code sign-in", async () => {
391+
fsStub.fake.readFile.rejects(new Error("File not found"))
392+
393+
const token = validToken()
394+
const fetchStub = sinon.stub(globalThis, "fetch")
395+
fetchStub.onFirstCall().resolves(
396+
mockResponse({
397+
device_code: "dev123",
398+
user_code: "USER-CODE",
399+
verification_uri: "https://auth.example.com/device",
400+
verification_uri_complete:
401+
"https://auth.example.com/device?code=USER-CODE",
402+
interval: 1,
403+
}),
404+
)
405+
fetchStub.onSecondCall().resolves(mockResponse({ access_token: token }))
406+
fetchStub
407+
.onThirdCall()
408+
.resolves(
409+
mockResponse({ email: "new@example.com", full_name: "New" }),
410+
)
411+
412+
sinon.stub(vscode.env, "openExternal")
413+
sinon
414+
.stub(vscode.window, "withProgress")
415+
.callsFake(async (_opts, task) => {
416+
const cancellationToken = {
417+
isCancellationRequested: false,
418+
onCancellationRequested: sinon.stub(),
419+
}
420+
return task({ report: sinon.stub() }, cancellationToken as any)
421+
})
422+
const infoStub = sinon.stub(vscode.window, "showInformationMessage")
423+
424+
fsStub.fake.createDirectory.resolves()
425+
fsStub.fake.writeFile.callsFake(async () => {
426+
fsStub.fake.readFile.resolves(
427+
Buffer.from(JSON.stringify({ access_token: token })),
428+
)
429+
})
430+
431+
const { provider } = createProvider()
432+
await provider.createSession()
433+
434+
assert.ok(
435+
infoStub.calledWith("Signed in to FastAPI Cloud as new@example.com"),
436+
)
437+
438+
await provider.dispose()
439+
})
440+
390441
test("wraps network error with friendly message", async () => {
391442
fsStub.fake.readFile.rejects(new Error("File not found"))
392443

0 commit comments

Comments
 (0)