-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
22 changed files
with
355 additions
and
219 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<script lang="ts"> | ||
import { setContext } from "svelte"; | ||
import { writable, type Writable } from "svelte/store"; | ||
import type { Org } from "@/api/types"; | ||
import { organization } from "@/test/fixtures/accounts"; | ||
const orgStore: Writable<Org> = writable(null); | ||
$: orgStore.set(organization as Org); | ||
setContext("org", orgStore); | ||
</script> | ||
|
||
<slot /> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
import { vi, test, describe, it, expect, beforeEach, afterEach } from "vitest"; | ||
|
||
import { BASE_API_URL } from "@/config/config"; | ||
import * as fixtures from "@/test/fixtures/accounts"; | ||
|
||
import { getMe, getOrg } from "./accounts"; | ||
|
||
describe("getMe", async () => { | ||
let mockFetch; | ||
beforeEach(() => { | ||
mockFetch = vi.fn().mockImplementation(async () => ({ | ||
ok: true, | ||
json: vi.fn().mockReturnValue(fixtures.me), | ||
})); | ||
}); | ||
afterEach(() => { | ||
vi.restoreAllMocks(); | ||
}); | ||
|
||
it("returns the expected data", async () => { | ||
const resp = await getMe(mockFetch); | ||
expect(resp).toBe(fixtures.me); | ||
}); | ||
|
||
it("calls the expected endpoint", async () => { | ||
await getMe(mockFetch); | ||
const expectedEndpoint = new URL(`users/me/`, BASE_API_URL); | ||
expectedEndpoint.searchParams.set("expand", "organization"); | ||
expect(mockFetch).toHaveBeenCalledWith(expectedEndpoint, { | ||
credentials: "include", | ||
}); | ||
}); | ||
|
||
it("returns undefined upon server error", async () => { | ||
mockFetch = vi.fn().mockImplementation(async () => ({ | ||
ok: false, | ||
json: vi.fn().mockReturnValue(fixtures.me), | ||
})); | ||
const resp = await getMe(mockFetch); | ||
expect(resp).toBeUndefined(); | ||
}); | ||
|
||
it("returns undefined upon fetch error", async () => { | ||
mockFetch = vi.fn().mockRejectedValue(new Error("Fetch Error")); | ||
const resp = await getMe(mockFetch); | ||
expect(resp).toBeUndefined(); | ||
}); | ||
}); | ||
|
||
test("getOrg", async () => { | ||
const mockFetch = vi.fn().mockImplementation(async () => ({ | ||
ok: true, | ||
json: vi.fn().mockReturnValue(fixtures.organization), | ||
})); | ||
const resp = await getOrg(mockFetch, 1); | ||
expect(resp).toEqual(fixtures.organization); | ||
expect(mockFetch).toHaveBeenCalledWith( | ||
new URL("organizations/1/", BASE_API_URL), | ||
{ credentials: "include" }, | ||
); | ||
}); | ||
|
||
test.todo("users.get"); | ||
test.todo("users.list"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import type { Maybe, User, Org } from "@/api/types"; | ||
import { BASE_API_URL } from "@/config/config.js"; | ||
|
||
type Fetch = typeof globalThis.fetch; | ||
|
||
/** Get the logged-in user */ | ||
export async function getMe(fetch: Fetch): Promise<Maybe<User>> { | ||
const endpoint = new URL("users/me/", BASE_API_URL); | ||
endpoint.searchParams.set("expand", "organization"); | ||
try { | ||
const resp = await fetch(endpoint, { credentials: "include" }); | ||
if (!resp.ok) return; | ||
return resp.json(); | ||
} catch (e) { | ||
return; | ||
} | ||
} | ||
|
||
export async function getOrg(fetch: Fetch, id: number): Promise<Org> { | ||
const endpoint = new URL(`organizations/${id}/`, BASE_API_URL); | ||
const resp = await fetch(endpoint, { credentials: "include" }); | ||
return resp.json(); | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,6 +23,7 @@ | |
flex: 1 0 0; | ||
align-self: stretch; | ||
position: relative; | ||
width: 100%; | ||
} | ||
header { | ||
flex: 0 0 0; | ||
|
Oops, something went wrong.