|
| 1 | +import {camelCaseKeys} from '~/helpers/page-data-utils'; |
| 2 | + |
| 3 | +export type AdoptionData = { |
| 4 | + adoptions: { |
| 5 | + baseYear: number; |
| 6 | + students: number | null; |
| 7 | + savings: number; |
| 8 | + }[]; |
| 9 | +}; |
| 10 | + |
| 11 | +type WindowWithSettings = typeof window & { |
| 12 | + SETTINGS: { |
| 13 | + accountHref: string; |
| 14 | + }; |
| 15 | +} |
| 16 | +const w = window as WindowWithSettings; |
| 17 | +const subdomains = ['staging.']; |
| 18 | +const subdomain = subdomains.find((sd) => w.SETTINGS.accountHref?.includes(sd)) || ''; |
| 19 | +const url = `https://${subdomain}salesforce.openstax.org/api/v1/adoptions`; |
| 20 | +const TESTING = process.env.JEST_WORKER_ID !== undefined; |
| 21 | +/* eslint-disable camelcase */ |
| 22 | +const testData = { |
| 23 | + count: 4, |
| 24 | + contact_id: '003U000001pyRebIAE', |
| 25 | + adoptions: [ |
| 26 | + { |
| 27 | + id: 'a00Pc000007TWN3IAO', |
| 28 | + book: { |
| 29 | + id: 'a0Z0B00000HPp9eUAD', |
| 30 | + name: 'Business Ethics', |
| 31 | + official_name: 'Introductory Business Ethics', |
| 32 | + type: 'General', |
| 33 | + subject_areas: 'Business', |
| 34 | + website_url: |
| 35 | + 'https://openstax.org/details/books/business-ethics' |
| 36 | + }, |
| 37 | + base_year: 2022, |
| 38 | + school_year: '2022 - 23', |
| 39 | + school: 'Test University', |
| 40 | + confirmation_type: 'User Behavior Informed Adoption', |
| 41 | + students: null, |
| 42 | + savings: 0.0, |
| 43 | + how_using: null, |
| 44 | + confirmation_date: '2023-04-03' |
| 45 | + }, |
| 46 | + { |
| 47 | + id: 'a00Pc000007TWN4IAO', |
| 48 | + book: { |
| 49 | + id: 'a0ZU0000008pytKMAQ', |
| 50 | + name: 'Biology', |
| 51 | + official_name: 'Biology', |
| 52 | + type: 'General', |
| 53 | + subject_areas: 'Science', |
| 54 | + website_url: 'https://openstax.org/details/books/biology' |
| 55 | + }, |
| 56 | + base_year: 2022, |
| 57 | + school_year: '2022 - 23', |
| 58 | + school: 'Test University', |
| 59 | + confirmation_type: 'User Behavior Informed Adoption', |
| 60 | + students: null, |
| 61 | + savings: 0.0, |
| 62 | + how_using: null, |
| 63 | + confirmation_date: '2023-02-21' |
| 64 | + }, |
| 65 | + { |
| 66 | + id: 'a00Pc000009o2B8IAI', |
| 67 | + book: { |
| 68 | + id: 'a0ZPc0000011zVVMAY', |
| 69 | + name: 'Calculus Volume 1', |
| 70 | + official_name: 'Calculus Volume 1', |
| 71 | + type: 'General', |
| 72 | + subject_areas: 'Math', |
| 73 | + website_url: |
| 74 | + 'https://openstax.org/details/books/calculus-volume-1' |
| 75 | + }, |
| 76 | + base_year: 2023, |
| 77 | + school_year: '2023 - 24', |
| 78 | + school: 'Test University', |
| 79 | + confirmation_type: 'OpenStax Confirmed Adoption', |
| 80 | + students: 50, |
| 81 | + savings: 3968.5, |
| 82 | + how_using: 'As the core textbook for my course', |
| 83 | + confirmation_date: '2024-03-04' |
| 84 | + }, |
| 85 | + { |
| 86 | + id: 'a00Pc00000BD2uRIAT', |
| 87 | + book: { |
| 88 | + id: 'a0ZU0000008pyv1MAA', |
| 89 | + name: 'Micro Econ', |
| 90 | + official_name: 'Principles of Microeconomics', |
| 91 | + type: 'General', |
| 92 | + subject_areas: 'Business;Social Sciences', |
| 93 | + website_url: |
| 94 | + 'https://openstax.org/details/books/principles-microeconomics' |
| 95 | + }, |
| 96 | + base_year: 2023, |
| 97 | + school_year: '2023 - 24', |
| 98 | + school: 'Test University', |
| 99 | + confirmation_type: 'User Behavior Informed Adoption', |
| 100 | + students: null, |
| 101 | + savings: 0.0, |
| 102 | + how_using: null, |
| 103 | + confirmation_date: '2024-03-26' |
| 104 | + } |
| 105 | + ], |
| 106 | + cache_create: '2024-04-12T16:17:43.345Z', |
| 107 | + cache_expire: '2024-04-12T17:17:43.345Z' |
| 108 | +}; |
| 109 | +const testPromise = Promise.resolve(testData); |
| 110 | + |
| 111 | +export default (TESTING ? testPromise : fetch(url).then((r) => r.json())).then( |
| 112 | + camelCaseKeys |
| 113 | +).catch(() => ({})); |
0 commit comments