From c7003082dc68129a039f736aba19bbe4bbd9df84 Mon Sep 17 00:00:00 2001 From: Allan Lasser Date: Tue, 26 Mar 2024 17:38:30 -0400 Subject: [PATCH 01/12] Refactors `src/addons` fixtures and handlers --- src/addons/browser/AddOnList.svelte | 11 +- .../browser/stories/AddOnList.stories.svelte | 4 +- .../browser/stories/Browser.stories.svelte | 2 +- src/addons/browser/stories/mockData.ts | 21 - src/addons/dispatch/Dispatch.svelte | 3 +- src/addons/dispatch/Form.svelte | 9 +- src/addons/dispatch/ScheduledInset.svelte | 4 +- .../dispatch/stories/Dispatch.stories.svelte | 57 +- .../dispatch/stories/Form.stories.svelte | 4 +- .../dispatch/stories/Header.stories.svelte | 4 +- .../dispatch/stories/Premium.stories.svelte | 4 +- .../stories/ScheduledInset.stories.svelte | 3 +- src/addons/fixtures/addon-list.json | 1083 ------ src/addons/fixtures/addon.json | 41 - src/addons/fixtures/addons-active.json | 251 -- src/addons/fixtures/addons.json | 631 ---- src/addons/fixtures/event-list.json | 200 -- src/addons/fixtures/event.json | 54 - src/addons/fixtures/klaxon-scheduled.json | 116 - src/addons/fixtures/premium-addon.json | 26 - src/addons/fixtures/run-list.json | 1148 ------ src/addons/fixtures/run.json | 84 - src/addons/progress/AddonRun.svelte | 2 +- .../progress/stories/AddonRun.stories.svelte | 4 +- .../stories/AddonStatus.stories.svelte | 2 +- src/addons/progress/stories/mockData.ts | 17 - src/addons/runs/History.svelte | 3 +- src/addons/runs/HistoryEvent.svelte | 25 +- src/addons/runs/Scheduled.svelte | 3 +- src/addons/runs/ScheduledEvent.svelte | 13 +- .../runs/stories/History.stories.svelte | 2 +- .../runs/stories/HistoryEvent.stories.svelte | 2 +- src/addons/runs/stories/Runs.stories.svelte | 2 +- .../runs/stories/Scheduled.stories.svelte | 2 +- .../stories/ScheduledEvent.stories.svelte | 2 +- src/addons/runs/stories/mockData.ts | 38 - src/addons/types.ts | 57 +- src/api/types/common.ts | 2 +- .../addons/stories/AddonList.stories.svelte | 2 +- src/pages/app/stories/mock.ts | 4 +- src/test/fixtures/addons.ts | 3147 +++++++++++++++++ src/test/handlers/addons.ts | 53 + 42 files changed, 3298 insertions(+), 3844 deletions(-) delete mode 100644 src/addons/browser/stories/mockData.ts delete mode 100644 src/addons/fixtures/addon-list.json delete mode 100644 src/addons/fixtures/addon.json delete mode 100644 src/addons/fixtures/addons-active.json delete mode 100644 src/addons/fixtures/addons.json delete mode 100644 src/addons/fixtures/event-list.json delete mode 100644 src/addons/fixtures/event.json delete mode 100644 src/addons/fixtures/klaxon-scheduled.json delete mode 100644 src/addons/fixtures/premium-addon.json delete mode 100644 src/addons/fixtures/run-list.json delete mode 100644 src/addons/fixtures/run.json delete mode 100644 src/addons/progress/stories/mockData.ts delete mode 100644 src/addons/runs/stories/mockData.ts create mode 100644 src/test/fixtures/addons.ts create mode 100644 src/test/handlers/addons.ts diff --git a/src/addons/browser/AddOnList.svelte b/src/addons/browser/AddOnList.svelte index b4ee58bf3..c174d1435 100644 --- a/src/addons/browser/AddOnList.svelte +++ b/src/addons/browser/AddOnList.svelte @@ -1,13 +1,3 @@ - - - diff --git a/src/addons/runs/Scheduled.svelte b/src/addons/runs/Scheduled.svelte index db3034548..c0c8880eb 100644 --- a/src/addons/runs/Scheduled.svelte +++ b/src/addons/runs/Scheduled.svelte @@ -7,7 +7,8 @@ import Error from "../../common/icons/Error.svelte"; import Loader from "../../common/Loader.svelte"; import Paginator from "../../common/Paginator.svelte"; - import ScheduledEvent, { type Event } from "./ScheduledEvent.svelte"; + import ScheduledEvent from "./ScheduledEvent.svelte"; + import type { Event } from "../types"; import { baseApiUrl } from "../../api/base.js"; diff --git a/src/addons/runs/ScheduledEvent.svelte b/src/addons/runs/ScheduledEvent.svelte index 08f751dc7..f39654eaf 100644 --- a/src/addons/runs/ScheduledEvent.svelte +++ b/src/addons/runs/ScheduledEvent.svelte @@ -1,16 +1,5 @@ {#if show} - +
Date: Tue, 26 Mar 2024 19:58:59 -0400 Subject: [PATCH 03/12] Consolidates remaining fixtures and handlers - Accounts - Documents - Projects with accompanying common fixtures and handler utils --- src/api/fixtures/orgAndUser.fixtures.ts | 237 --- src/api/fixtures/projects.fixtures.ts | 109 -- src/api/types/document.ts | 9 +- src/api/types/orgAndUser.ts | 7 +- .../stories/ProjectDialog.stories.svelte | 2 +- .../stories/RevisionsDialog.stories.svelte | 7 +- src/common/dialog/stories/mockData.ts | 14 - .../stories/AccountNavigation.stories.svelte | 2 +- .../stories/OrgMemberList.stories.svelte | 2 +- .../accounts/stories/OrgMenu.stories.svelte | 11 +- .../stories/PremiumMenu.stories.svelte | 6 +- src/pages/app/accounts/stories/mockData.ts | 140 -- src/pages/app/fixtures/addon_runs.json | 1 - src/pages/app/fixtures/document.json | 46 - src/pages/app/fixtures/documents.json | 1157 --------------- src/pages/app/fixtures/me.json | 32 - src/pages/app/fixtures/organizations.json | 95 -- src/pages/app/fixtures/users.json | 227 --- .../addons/stories/AddonList.stories.svelte | 2 +- .../stories/ProjectList.stories.svelte | 2 +- .../stories/DocumentFilters.stories.svelte | 9 +- .../sidebar/stories/Sidebar.stories.svelte | 8 +- src/pages/app/stories/mock.ts | 69 - src/pages/app/test/fixtures/document.json | 74 - .../app/test/stories/Document.stories.svelte | 4 +- .../stories/DocumentThumbnail.stories.svelte | 6 +- src/pages/viewer/fixtures/document.json | 74 - src/projects/stories/mockData.ts | 19 - src/test/fixtures/accounts.ts | 419 ++++++ .../empty.ts => test/fixtures/common.ts} | 2 +- src/test/fixtures/documents.ts | 1274 +++++++++++++++++ .../project.ts => test/fixtures/projects.ts} | 49 +- src/test/handlers/accounts.ts | 132 ++ src/test/handlers/addons.ts | 42 +- src/test/handlers/documents.ts | 16 + src/test/handlers/projects.ts | 4 + src/test/handlers/utils.ts | 34 + 37 files changed, 1968 insertions(+), 2375 deletions(-) delete mode 100644 src/api/fixtures/orgAndUser.fixtures.ts delete mode 100644 src/api/fixtures/projects.fixtures.ts delete mode 100644 src/common/dialog/stories/mockData.ts delete mode 100644 src/pages/app/accounts/stories/mockData.ts delete mode 100644 src/pages/app/fixtures/addon_runs.json delete mode 100644 src/pages/app/fixtures/document.json delete mode 100644 src/pages/app/fixtures/documents.json delete mode 100644 src/pages/app/fixtures/me.json delete mode 100644 src/pages/app/fixtures/organizations.json delete mode 100644 src/pages/app/fixtures/users.json delete mode 100644 src/pages/app/stories/mock.ts delete mode 100644 src/pages/app/test/fixtures/document.json delete mode 100644 src/pages/viewer/fixtures/document.json delete mode 100644 src/projects/stories/mockData.ts create mode 100644 src/test/fixtures/accounts.ts rename src/{api/test/fixtures/empty.ts => test/fixtures/common.ts} (67%) create mode 100644 src/test/fixtures/documents.ts rename src/{api/test/fixtures/project.ts => test/fixtures/projects.ts} (87%) create mode 100644 src/test/handlers/accounts.ts create mode 100644 src/test/handlers/documents.ts create mode 100644 src/test/handlers/projects.ts create mode 100644 src/test/handlers/utils.ts diff --git a/src/api/fixtures/orgAndUser.fixtures.ts b/src/api/fixtures/orgAndUser.fixtures.ts deleted file mode 100644 index 3626d5bf8..000000000 --- a/src/api/fixtures/orgAndUser.fixtures.ts +++ /dev/null @@ -1,237 +0,0 @@ -import { Org, Page, User } from "../types"; -import { GroupOrg, IndividualOrg } from "../types/orgAndUser"; - -export const me: User = { - id: 4, - avatar_url: - "https://cdn.muckrock.com/media/account_images/allan-headshot-2016.jpg", - feature_level: 2, - name: "Allan Lasser", - organization: { - id: 1, - avatar_url: - "https://squarelet-staging.s3.amazonaws.com/media/org_avatars/logo_uEHCMva.png", - individual: false, - name: "MuckRock", - slug: "muckrock", - monthly_credits: 5000, - purchased_credits: 0, - credit_reset_date: "2023-11-28", - monthly_credit_allowance: 5000, - plan: "Organization", - }, - organizations: [1, 4], - admin_organizations: [40742], - username: "lasser.allan", - verified_journalist: true, -}; - -export const users: Page = { - next: null, - previous: null, - count: 12, - results: [ - { - id: 1, - avatar_url: - "https://cdn.muckrock.com/media/avatars/Michael_Headshot.jpeg", - name: "Michael Morisy", - organization: 1, - organizations: [1, 10], - admin_organizations: [1, 10], - username: "morisy", - verified_journalist: true, - }, - { - id: 2, - avatar_url: - "https://cdn.muckrock.com/media/avatars/20140211-0O1A7147-2.jpg", - name: "Chris Amico", - organization: 1, - organizations: [1, 11], - admin_organizations: [11], - username: "chrisamico", - verified_journalist: true, - }, - { - id: 3, - avatar_url: - "https://cdn.muckrock.com/media/account_images/22_MuckRock_2018_PRELIMANRY_EDITS_DSC_5387_2018_Derek_Kouyoumjian_preview_SfuGGnJ.jpg", - name: "Mitchell Kotler", - organization: 1, - organizations: [1, 12], - admin_organizations: [1, 12], - username: "mitch", - verified_journalist: true, - }, - { - id: 4, - avatar_url: - "https://cdn.muckrock.com/media/account_images/allan-headshot-2016.jpg", - name: "Allan Lasser", - organization: 1, - organizations: [1, 13], - admin_organizations: [13], - username: "lasser.allan", - verified_journalist: true, - }, - { - id: 5, - avatar_url: - "https://cdn.muckrock.com/media/avatars/noah_oct2021_vsco_cropped_smaller.gif", - name: "Amanda Hickman", - organization: 1, - organizations: [1, 14], - admin_organizations: [1, 14], - username: "amandabee", - verified_journalist: true, - }, - { - id: 6, - avatar_url: - "https://cdn.muckrock.com/media/avatars/derek-crop-square_Rx7mFk8.jpg", - name: "Derek Kravitz", - organization: 1, - organizations: [1, 15], - admin_organizations: [1, 15], - username: "DerekRKravitz", - verified_journalist: true, - }, - { - id: 7, - avatar_url: null, - name: "Miranda Carruth", - organization: 1, - organizations: [1, 16], - admin_organizations: [16], - username: "mirandac", - }, - { - id: 8, - avatar_url: "https://cdn.muckrock.com/media/avatars/kelly-square.jpg", - name: "Kelly Kauffman", - organization: 1, - organizations: [1, 17], - admin_organizations: [17], - username: "kellykauffman", - verified_journalist: true, - }, - { - id: 9, - avatar_url: "https://cdn.muckrock.com/media/avatars/Albert_Serna_Jr.jpg", - name: "Albert Serna Jr.", - organization: 1, - organizations: [1, 18], - admin_organizations: [18], - username: "AlbertSGJ", - verified_journalist: true, - }, - { - id: 10, - avatar_url: "https://cdn.muckrock.com/media/avatars/under.jpg", - name: "JPat Brown", - organization: 1, - organizations: [1, 19], - admin_organizations: [19], - username: "JPatBrown", - verified_journalist: true, - }, - { - id: 11, - avatar_url: null, - name: "Scott Klein", - organization: 1, - organizations: [1, 20], - admin_organizations: [20], - username: "ScottKlein", - verified_journalist: true, - }, - { - id: 12, - avatar_url: - "https://cdn.muckrock.com/media/account_images/1_Nz2NFvHxTjqw5asaiPKf5w_sssJnjW.jpg", - name: "Aron Pilhofer", - organization: 1, - organizations: [1, 21], - admin_organizations: [22], - username: "Pilhofer", - verified_journalist: true, - }, - ], -}; - -export const organizations: Page = { - next: null, - previous: null, - count: 2, - results: [ - { - id: 1, - avatar_url: - "https://squarelet-staging.s3.amazonaws.com/media/org_avatars/logo_uEHCMva.png", - individual: false, - name: "MuckRock", - slug: "muckrock", - monthly_credits: 5000, - purchased_credits: 0, - credit_reset_date: "2023-11-28", - monthly_credit_allowance: 5000, - plan: "Organization", - }, - { - id: 4, - avatar_url: - "https://cdn.muckrock.com/media/account_images/allan-headshot-2016.jpg", - individual: true, - name: "lasser.allan", - slug: "lasserallan", - monthly_credits: 2500, - purchased_credits: 3000, - credit_reset_date: "2023-11-28", - monthly_credit_allowance: 2500, - plan: "Professional", - }, - ], -}; - -export const organization: GroupOrg = { - id: 1, - avatar_url: - "https://squarelet-staging.s3.amazonaws.com/media/org_avatars/logo_uEHCMva.png", - individual: false, - name: "MuckRock", - slug: "muckrock", - monthly_credits: 5000, - purchased_credits: 0, - credit_reset_date: "2023-11-28", - monthly_credit_allowance: 5000, - plan: "Organization", -}; - -export const proOrg: IndividualOrg = { - id: 4, - avatar_url: - "https://cdn.muckrock.com/media/account_images/allan-headshot-2016.jpg", - individual: true, - name: "lasser.allan", - slug: "lasserallan", - monthly_credits: 2500, - purchased_credits: 3000, - credit_reset_date: "2023-11-28", - monthly_credit_allowance: 2500, - plan: "Professional", -}; - -export const freeOrg: IndividualOrg = { - id: 4, - avatar_url: - "https://cdn.muckrock.com/media/account_images/allan-headshot-2016.jpg", - individual: true, - name: "lasser.allan", - slug: "lasserallan", - monthly_credits: 0, - purchased_credits: 0, - credit_reset_date: "2023-11-28", - monthly_credit_allowance: 0, - plan: "Free", -}; diff --git a/src/api/fixtures/projects.fixtures.ts b/src/api/fixtures/projects.fixtures.ts deleted file mode 100644 index 669f968fd..000000000 --- a/src/api/fixtures/projects.fixtures.ts +++ /dev/null @@ -1,109 +0,0 @@ -import { Page, Project } from "../types"; - -export let project: Project = { - id: 29, - created_at: "2020-10-23T15:59:33.779478Z", - description: "", - edit_access: null, - add_remove_access: null, - private: false, - slug: "miltary-contractors", - title: "Miltary Contractors", - updated_at: "2020-10-23T15:59:33.896698Z", - user: 1, -}; - -export let editableProject: Project = { - id: 29, - created_at: "2020-10-23T15:59:33.779478Z", - description: "", - edit_access: true, - add_remove_access: null, - private: false, - slug: "miltary-contractors", - title: "Miltary Contractors", - updated_at: "2020-10-23T15:59:33.896698Z", - user: 1, -}; - -export let projects: Page = { - next: null, - previous: null, - count: 5, - results: [ - { - id: 2, - created_at: "2020-10-27T16:48:08.161751Z", - description: "A sample set. ", - edit_access: null, - add_remove_access: null, - private: true, - slug: "defense-dept-foia", - title: "Defense Dept FOIA", - updated_at: "2020-10-27T16:48:08.168482Z", - user: 4, - pinned: true, - }, - { - id: 5, - created_at: "2020-11-10T16:24:55.027446Z", - description: - "DOJ Report on Bush Administration Interrogation Memos and Related Documents released by the house judiciary committee in March 2010.", - edit_access: null, - add_remove_access: null, - private: false, - slug: "interrogation-memo-report-doj", - title: "Interrogation Memo Report (DOJ)", - updated_at: "2020-11-10T16:24:55.070632Z", - user: 4, - }, - { - id: 6, - created_at: "2020-11-10T16:24:55.027659Z", - description: "", - edit_access: null, - add_remove_access: null, - private: false, - slug: "the-financial-crisis", - title: "The Financial Crisis", - updated_at: "2020-11-10T16:24:55.071378Z", - user: 1, - }, - { - id: 17, - created_at: "2020-11-10T16:24:55.036977Z", - description: "", - edit_access: null, - add_remove_access: null, - private: false, - slug: "pulitzer-please", - title: "Pulitzer, Please", - updated_at: "2020-11-10T16:24:55.097554Z", - user: 14, - }, - { - id: 20, - created_at: "2020-11-10T16:09:05.829402Z", - description: "", - edit_access: null, - add_remove_access: null, - private: false, - slug: "illinois", - title: "illinois", - updated_at: "2020-11-10T16:09:05.873311Z", - user: 3, - }, - { - id: 21, - created_at: "2020-11-10T16:24:55.038969Z", - description: "", - edit_access: null, - add_remove_access: null, - private: false, - slug: "documentcloud", - title: "DocumentCloud", - updated_at: "2020-11-10T16:24:55.103407Z", - user: 4, - }, - ], -}; diff --git a/src/api/types/document.ts b/src/api/types/document.ts index 33283c5c1..a1806fb62 100644 --- a/src/api/types/document.ts +++ b/src/api/types/document.ts @@ -1,4 +1,5 @@ import { Nullable } from "./common"; +import { Org, User } from "./orgAndUser"; import { Project } from "./project"; export type DocumentAccess = "public" | "organization" | "private"; @@ -24,11 +25,13 @@ export interface Document { file_hash: string; noindex: boolean; language: string; - organization: number; + organization: Org | number; original_extension: string; page_count: number; page_spec: string; - projects: Project[]; + projects: (Project | number)[]; + notes?: []; + sections?: []; publish_at: Nullable; published_url: string; related_article: string; @@ -39,5 +42,5 @@ export interface Document { status: "success" | "failure" | "queued" | "in_progress"; title: string; updated_at: string; - user: number; + user: User | number; } diff --git a/src/api/types/orgAndUser.ts b/src/api/types/orgAndUser.ts index a934c7233..d558592cd 100644 --- a/src/api/types/orgAndUser.ts +++ b/src/api/types/orgAndUser.ts @@ -8,12 +8,13 @@ interface PremiumOrgFields { } export interface Org extends Partial { + uuid: string; id: number; name: string; slug: string; avatar_url: string; - individual: boolean; - plan: "Free" | "Professional" | "Organization"; + individual?: boolean; + plan?: "Free" | "Professional" | "Organization"; } export interface GroupOrg extends Org { @@ -27,6 +28,7 @@ export interface IndividualOrg extends Org { } export interface User { + uuid: string; id: number; name: Maybe; avatar_url: Maybe; @@ -36,6 +38,7 @@ export interface User { admin_organizations: number[]; feature_level?: number; verified_journalist?: boolean; + is_staff?: boolean; } export function isOrg(org?: null | number | Org): org is Org { diff --git a/src/common/dialog/stories/ProjectDialog.stories.svelte b/src/common/dialog/stories/ProjectDialog.stories.svelte index b2155570a..dd61b01bd 100644 --- a/src/common/dialog/stories/ProjectDialog.stories.svelte +++ b/src/common/dialog/stories/ProjectDialog.stories.svelte @@ -1,7 +1,7 @@