From 075da01a279f5515f5212c4e8df5ca3b532b3e7e Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 13 Nov 2023 15:26:38 +0000 Subject: [PATCH 1/5] chore(deps): bump the major-production-dependencies group with 1 update Bumps the major-production-dependencies group with 1 update: [next](https://github.com/vercel/next.js). - [Release notes](https://github.com/vercel/next.js/releases) - [Changelog](https://github.com/vercel/next.js/blob/canary/release.js) - [Commits](https://github.com/vercel/next.js/compare/v13.4.7...v14.0.2) --- updated-dependencies: - dependency-name: next dependency-type: direct:production update-type: version-update:semver-major dependency-group: major-production-dependencies ... Signed-off-by: dependabot[bot] --- package-lock.json | 139 +++++++++++++++++----------------------------- package.json | 2 +- 2 files changed, 52 insertions(+), 89 deletions(-) diff --git a/package-lock.json b/package-lock.json index 12b5531..1e6b07d 100644 --- a/package-lock.json +++ b/package-lock.json @@ -8,7 +8,7 @@ "name": "team-availability", "version": "0.1.0", "dependencies": { - "next": "13.4.7", + "next": "14.0.2", "react": "18.2.0", "react-dom": "18.2.0" }, @@ -1423,9 +1423,9 @@ } }, "node_modules/@next/env": { - "version": "13.4.7", - "resolved": "https://registry.npmjs.org/@next/env/-/env-13.4.7.tgz", - "integrity": "sha512-ZlbiFulnwiFsW9UV1ku1OvX/oyIPLtMk9p/nnvDSwI0s7vSoZdRtxXNsaO+ZXrLv/pMbXVGq4lL8TbY9iuGmVw==" + "version": "14.0.2", + "resolved": "https://registry.npmjs.org/@next/env/-/env-14.0.2.tgz", + "integrity": "sha512-HAW1sljizEaduEOes/m84oUqeIDAUYBR1CDwu2tobNlNDFP3cSm9d6QsOsGeNlIppU1p/p1+bWbYCbvwjFiceA==" }, "node_modules/@next/eslint-plugin-next": { "version": "14.0.2", @@ -1437,9 +1437,9 @@ } }, "node_modules/@next/swc-darwin-arm64": { - "version": "13.4.7", - "resolved": "https://registry.npmjs.org/@next/swc-darwin-arm64/-/swc-darwin-arm64-13.4.7.tgz", - "integrity": "sha512-VZTxPv1b59KGiv/pZHTO5Gbsdeoxcj2rU2cqJu03btMhHpn3vwzEK0gUSVC/XW96aeGO67X+cMahhwHzef24/w==", + "version": "14.0.2", + "resolved": "https://registry.npmjs.org/@next/swc-darwin-arm64/-/swc-darwin-arm64-14.0.2.tgz", + "integrity": "sha512-i+jQY0fOb8L5gvGvojWyZMfQoQtDVB2kYe7fufOEiST6sicvzI2W5/EXo4lX5bLUjapHKe+nFxuVv7BA+Pd7LQ==", "cpu": [ "arm64" ], @@ -1452,9 +1452,9 @@ } }, "node_modules/@next/swc-darwin-x64": { - "version": "13.4.7", - "resolved": "https://registry.npmjs.org/@next/swc-darwin-x64/-/swc-darwin-x64-13.4.7.tgz", - "integrity": "sha512-gO2bw+2Ymmga+QYujjvDz9955xvYGrWofmxTq7m70b9pDPvl7aDFABJOZ2a8SRCuSNB5mXU8eTOmVVwyp/nAew==", + "version": "14.0.2", + "resolved": "https://registry.npmjs.org/@next/swc-darwin-x64/-/swc-darwin-x64-14.0.2.tgz", + "integrity": "sha512-zRCAO0d2hW6gBEa4wJaLn+gY8qtIqD3gYd9NjruuN98OCI6YyelmhWVVLlREjS7RYrm9OUQIp/iVJFeB6kP1hg==", "cpu": [ "x64" ], @@ -1467,9 +1467,9 @@ } }, "node_modules/@next/swc-linux-arm64-gnu": { - "version": "13.4.7", - "resolved": "https://registry.npmjs.org/@next/swc-linux-arm64-gnu/-/swc-linux-arm64-gnu-13.4.7.tgz", - "integrity": "sha512-6cqp3vf1eHxjIDhEOc7Mh/s8z1cwc/l5B6ZNkOofmZVyu1zsbEM5Hmx64s12Rd9AYgGoiCz4OJ4M/oRnkE16/Q==", + "version": "14.0.2", + "resolved": "https://registry.npmjs.org/@next/swc-linux-arm64-gnu/-/swc-linux-arm64-gnu-14.0.2.tgz", + "integrity": "sha512-tSJmiaon8YaKsVhi7GgRizZoV0N1Sx5+i+hFTrCKKQN7s3tuqW0Rov+RYdPhAv/pJl4qiG+XfSX4eJXqpNg3dA==", "cpu": [ "arm64" ], @@ -1482,9 +1482,9 @@ } }, "node_modules/@next/swc-linux-arm64-musl": { - "version": "13.4.7", - "resolved": "https://registry.npmjs.org/@next/swc-linux-arm64-musl/-/swc-linux-arm64-musl-13.4.7.tgz", - "integrity": "sha512-T1kD2FWOEy5WPidOn1si0rYmWORNch4a/NR52Ghyp4q7KyxOCuiOfZzyhVC5tsLIBDH3+cNdB5DkD9afpNDaOw==", + "version": "14.0.2", + "resolved": "https://registry.npmjs.org/@next/swc-linux-arm64-musl/-/swc-linux-arm64-musl-14.0.2.tgz", + "integrity": "sha512-dXJLMSEOwqJKcag1BeX1C+ekdPPJ9yXbWIt3nAadhbLx5CjACoB2NQj9Xcqu2tmdr5L6m34fR+fjGPs+ZVPLzA==", "cpu": [ "arm64" ], @@ -1497,9 +1497,9 @@ } }, "node_modules/@next/swc-linux-x64-gnu": { - "version": "13.4.7", - "resolved": "https://registry.npmjs.org/@next/swc-linux-x64-gnu/-/swc-linux-x64-gnu-13.4.7.tgz", - "integrity": "sha512-zaEC+iEiAHNdhl6fuwl0H0shnTzQoAoJiDYBUze8QTntE/GNPfTYpYboxF5LRYIjBwETUatvE0T64W6SKDipvg==", + "version": "14.0.2", + "resolved": "https://registry.npmjs.org/@next/swc-linux-x64-gnu/-/swc-linux-x64-gnu-14.0.2.tgz", + "integrity": "sha512-WC9KAPSowj6as76P3vf1J3mf2QTm3Wv3FBzQi7UJ+dxWjK3MhHVWsWUo24AnmHx9qDcEtHM58okgZkXVqeLB+Q==", "cpu": [ "x64" ], @@ -1512,9 +1512,9 @@ } }, "node_modules/@next/swc-linux-x64-musl": { - "version": "13.4.7", - "resolved": "https://registry.npmjs.org/@next/swc-linux-x64-musl/-/swc-linux-x64-musl-13.4.7.tgz", - "integrity": "sha512-X6r12F8d8SKAtYJqLZBBMIwEqcTRvUdVm+xIq+l6pJqlgT2tNsLLf2i5Cl88xSsIytBICGsCNNHd+siD2fbWBA==", + "version": "14.0.2", + "resolved": "https://registry.npmjs.org/@next/swc-linux-x64-musl/-/swc-linux-x64-musl-14.0.2.tgz", + "integrity": "sha512-KSSAwvUcjtdZY4zJFa2f5VNJIwuEVnOSlqYqbQIawREJA+gUI6egeiRu290pXioQXnQHYYdXmnVNZ4M+VMB7KQ==", "cpu": [ "x64" ], @@ -1527,9 +1527,9 @@ } }, "node_modules/@next/swc-win32-arm64-msvc": { - "version": "13.4.7", - "resolved": "https://registry.npmjs.org/@next/swc-win32-arm64-msvc/-/swc-win32-arm64-msvc-13.4.7.tgz", - "integrity": "sha512-NPnmnV+vEIxnu6SUvjnuaWRglZzw4ox5n/MQTxeUhb5iwVWFedolPFebMNwgrWu4AELwvTdGtWjqof53AiWHcw==", + "version": "14.0.2", + "resolved": "https://registry.npmjs.org/@next/swc-win32-arm64-msvc/-/swc-win32-arm64-msvc-14.0.2.tgz", + "integrity": "sha512-2/O0F1SqJ0bD3zqNuYge0ok7OEWCQwk55RPheDYD0va5ij7kYwrFkq5ycCRN0TLjLfxSF6xI5NM6nC5ux7svEQ==", "cpu": [ "arm64" ], @@ -1542,9 +1542,9 @@ } }, "node_modules/@next/swc-win32-ia32-msvc": { - "version": "13.4.7", - "resolved": "https://registry.npmjs.org/@next/swc-win32-ia32-msvc/-/swc-win32-ia32-msvc-13.4.7.tgz", - "integrity": "sha512-6Hxijm6/a8XqLQpOOf/XuwWRhcuc/g4rBB2oxjgCMuV9Xlr2bLs5+lXyh8w9YbAUMYR3iC9mgOlXbHa79elmXw==", + "version": "14.0.2", + "resolved": "https://registry.npmjs.org/@next/swc-win32-ia32-msvc/-/swc-win32-ia32-msvc-14.0.2.tgz", + "integrity": "sha512-vJI/x70Id0oN4Bq/R6byBqV1/NS5Dl31zC+lowO8SDu1fHmUxoAdILZR5X/sKbiJpuvKcCrwbYgJU8FF/Gh50Q==", "cpu": [ "ia32" ], @@ -1557,9 +1557,9 @@ } }, "node_modules/@next/swc-win32-x64-msvc": { - "version": "13.4.7", - "resolved": "https://registry.npmjs.org/@next/swc-win32-x64-msvc/-/swc-win32-x64-msvc-13.4.7.tgz", - "integrity": "sha512-sW9Yt36Db1nXJL+mTr2Wo0y+VkPWeYhygvcHj1FF0srVtV+VoDjxleKtny21QHaG05zdeZnw2fCtf2+dEqgwqA==", + "version": "14.0.2", + "resolved": "https://registry.npmjs.org/@next/swc-win32-x64-msvc/-/swc-win32-x64-msvc-14.0.2.tgz", + "integrity": "sha512-Ut4LXIUvC5m8pHTe2j0vq/YDnTEyq6RSR9vHYPqnELrDapPhLNz9Od/L5Ow3J8RNDWpEnfCiQXuVdfjlNEJ7ug==", "cpu": [ "x64" ], @@ -1637,9 +1637,9 @@ } }, "node_modules/@swc/helpers": { - "version": "0.5.1", - "resolved": "https://registry.npmjs.org/@swc/helpers/-/helpers-0.5.1.tgz", - "integrity": "sha512-sJ902EfIzn1Fa+qYmjdQqh8tPsoxyBz+8yBKC2HKUxyezKJFwPGOn7pv4WY6QuQW//ySQi5lJjA/ZT9sNWWNTg==", + "version": "0.5.2", + "resolved": "https://registry.npmjs.org/@swc/helpers/-/helpers-0.5.2.tgz", + "integrity": "sha512-E4KcWTpoLHqwPHLxidpOqQbcrZVgi0rsmmZXUle1jXmJfuIf/UWpczUJ7MZZ5tlxytgJXyp0w4PGkkeLiuIdZw==", "dependencies": { "tslib": "^2.4.0" } @@ -7125,39 +7125,37 @@ "dev": true }, "node_modules/next": { - "version": "13.4.7", - "resolved": "https://registry.npmjs.org/next/-/next-13.4.7.tgz", - "integrity": "sha512-M8z3k9VmG51SRT6v5uDKdJXcAqLzP3C+vaKfLIAM0Mhx1um1G7MDnO63+m52qPdZfrTFzMZNzfsgvm3ghuVHIQ==", + "version": "14.0.2", + "resolved": "https://registry.npmjs.org/next/-/next-14.0.2.tgz", + "integrity": "sha512-jsAU2CkYS40GaQYOiLl9m93RTv2DA/tTJ0NRlmZIBIL87YwQ/xR8k796z7IqgM3jydI8G25dXvyYMC9VDIevIg==", "dependencies": { - "@next/env": "13.4.7", - "@swc/helpers": "0.5.1", + "@next/env": "14.0.2", + "@swc/helpers": "0.5.2", "busboy": "1.6.0", "caniuse-lite": "^1.0.30001406", - "postcss": "8.4.14", + "postcss": "8.4.31", "styled-jsx": "5.1.1", - "watchpack": "2.4.0", - "zod": "3.21.4" + "watchpack": "2.4.0" }, "bin": { "next": "dist/bin/next" }, "engines": { - "node": ">=16.8.0" + "node": ">=18.17.0" }, "optionalDependencies": { - "@next/swc-darwin-arm64": "13.4.7", - "@next/swc-darwin-x64": "13.4.7", - "@next/swc-linux-arm64-gnu": "13.4.7", - "@next/swc-linux-arm64-musl": "13.4.7", - "@next/swc-linux-x64-gnu": "13.4.7", - "@next/swc-linux-x64-musl": "13.4.7", - "@next/swc-win32-arm64-msvc": "13.4.7", - "@next/swc-win32-ia32-msvc": "13.4.7", - "@next/swc-win32-x64-msvc": "13.4.7" + "@next/swc-darwin-arm64": "14.0.2", + "@next/swc-darwin-x64": "14.0.2", + "@next/swc-linux-arm64-gnu": "14.0.2", + "@next/swc-linux-arm64-musl": "14.0.2", + "@next/swc-linux-x64-gnu": "14.0.2", + "@next/swc-linux-x64-musl": "14.0.2", + "@next/swc-win32-arm64-msvc": "14.0.2", + "@next/swc-win32-ia32-msvc": "14.0.2", + "@next/swc-win32-x64-msvc": "14.0.2" }, "peerDependencies": { "@opentelemetry/api": "^1.1.0", - "fibers": ">= 3.1.0", "react": "^18.2.0", "react-dom": "^18.2.0", "sass": "^1.3.0" @@ -7166,37 +7164,11 @@ "@opentelemetry/api": { "optional": true }, - "fibers": { - "optional": true - }, "sass": { "optional": true } } }, - "node_modules/next/node_modules/postcss": { - "version": "8.4.14", - "resolved": "https://registry.npmjs.org/postcss/-/postcss-8.4.14.tgz", - "integrity": "sha512-E398TUmfAYFPBSdzgeieK2Y1+1cpdxJx8yXbK/m57nRhKSmk1GB2tO4lbLBtlkfPQTDKfe4Xqv1ASWPpayPEig==", - "funding": [ - { - "type": "opencollective", - "url": "https://opencollective.com/postcss/" - }, - { - "type": "tidelift", - "url": "https://tidelift.com/funding/github/npm/postcss" - } - ], - "dependencies": { - "nanoid": "^3.3.4", - "picocolors": "^1.0.0", - "source-map-js": "^1.0.2" - }, - "engines": { - "node": "^10 || ^12 || >=14" - } - }, "node_modules/nice-try": { "version": "1.0.5", "resolved": "https://registry.npmjs.org/nice-try/-/nice-try-1.0.5.tgz", @@ -7839,7 +7811,6 @@ "version": "8.4.31", "resolved": "https://registry.npmjs.org/postcss/-/postcss-8.4.31.tgz", "integrity": "sha512-PS08Iboia9mts/2ygV3eLpY5ghnUcfLV/EXTOW1E2qYxJKGGBUtNjN76FYHnMs36RmARn41bC0AZmn+rR0OVpQ==", - "dev": true, "funding": [ { "type": "opencollective", @@ -9887,14 +9858,6 @@ "funding": { "url": "https://github.com/sponsors/sindresorhus" } - }, - "node_modules/zod": { - "version": "3.21.4", - "resolved": "https://registry.npmjs.org/zod/-/zod-3.21.4.tgz", - "integrity": "sha512-m46AKbrzKVzOzs/DZgVnG5H55N1sv1M8qZU3A8RIKbs3mrACDNeIOeilDymVb2HdmP8uwshOCF4uJ8uM9rCqJw==", - "funding": { - "url": "https://github.com/sponsors/colinhacks" - } } } } diff --git a/package.json b/package.json index 56c05e5..e20644d 100644 --- a/package.json +++ b/package.json @@ -15,7 +15,7 @@ "node": ">=20" }, "dependencies": { - "next": "13.4.7", + "next": "14.0.2", "react": "18.2.0", "react-dom": "18.2.0" }, From 010ffbea17235fe391430b4a16dd3b1ab32a2804 Mon Sep 17 00:00:00 2001 From: dustin-jw Date: Mon, 13 Nov 2023 08:28:42 -0700 Subject: [PATCH 2/5] chore: specify node version for production build --- .node-version | 1 + 1 file changed, 1 insertion(+) create mode 100644 .node-version diff --git a/.node-version b/.node-version new file mode 100644 index 0000000..f3f52b4 --- /dev/null +++ b/.node-version @@ -0,0 +1 @@ +20.9.0 From 826a72577f2e19694035d294fa72321aa582224a Mon Sep 17 00:00:00 2001 From: dustin-jw Date: Mon, 13 Nov 2023 08:36:06 -0700 Subject: [PATCH 3/5] chore: change output mode to export --- next.config.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/next.config.js b/next.config.js index a843cbe..2f7f50e 100644 --- a/next.config.js +++ b/next.config.js @@ -1,6 +1,7 @@ /** @type {import('next').NextConfig} */ const nextConfig = { reactStrictMode: true, -} + output: 'export', +}; -module.exports = nextConfig +module.exports = nextConfig; From a7e1a75f66171e3001215221bc803dbdce4fbb5e Mon Sep 17 00:00:00 2001 From: dustin-jw Date: Mon, 13 Nov 2023 09:06:13 -0700 Subject: [PATCH 4/5] feat: statically generate pages --- __tests__/[id].test.jsx | 70 ++++++++++++++++++++--------------------- next.config.js | 1 - pages/[id].jsx | 31 ++++++++++++------ pages/index.jsx | 14 +++++---- 4 files changed, 64 insertions(+), 52 deletions(-) diff --git a/__tests__/[id].test.jsx b/__tests__/[id].test.jsx index 6e8fcee..87a7383 100644 --- a/__tests__/[id].test.jsx +++ b/__tests__/[id].test.jsx @@ -3,7 +3,7 @@ import '@testing-library/jest-dom'; import { FilterProvider } from '../context/FilterContext'; import { ViewProvider } from '../context/ViewContext'; import apiService from '../services/apiService'; -import DetailPage, { getServerSideProps } from '../pages/[id]'; +import DetailPage, { getStaticProps } from '../pages/[id]'; const MOCK_TEAM_MEMBER = { firstName: 'Aragorn', @@ -39,38 +39,38 @@ describe('DetailPage', () => { }); }); -describe('getServerSideProps', () => { - it('calls getMemberById', async () => { - const context = { - params: { - id: '0001', - }, - req: { - headers: { - host: 'localhost:3000', - }, - }, - }; - const response = await getServerSideProps(context); +// describe('getStaticProps', () => { +// it('calls getMemberById', async () => { +// const context = { +// params: { +// id: '0001', +// }, +// req: { +// headers: { +// host: 'localhost:3000', +// }, +// }, +// }; +// const response = await getStaticProps(context); - expect(response).toEqual( - expect.objectContaining({ - props: { - fetchedTeamMember: { - firstName: 'Aragorn', - lastName: 'Elessar', - suffix: 'II', - photo: '/images/mock/aragorn.png', - currentProjects: [], - pastProjects: [''], - funFacts: [], - weeklyCapacity: 32, - forecastedHours: [11, 23], - cohortLeader: 'fellowship', - cohortParticipant: 'fellowship', - }, - }, - }) - ); - }); -}); +// expect(response).toEqual( +// expect.objectContaining({ +// props: { +// fetchedTeamMember: { +// firstName: 'Aragorn', +// lastName: 'Elessar', +// suffix: 'II', +// photo: '/images/mock/aragorn.png', +// currentProjects: [], +// pastProjects: [''], +// funFacts: [], +// weeklyCapacity: 32, +// forecastedHours: [11, 23], +// cohortLeader: 'fellowship', +// cohortParticipant: 'fellowship', +// }, +// }, +// }) +// ); +// }); +// }); diff --git a/next.config.js b/next.config.js index 2f7f50e..91ef62f 100644 --- a/next.config.js +++ b/next.config.js @@ -1,7 +1,6 @@ /** @type {import('next').NextConfig} */ const nextConfig = { reactStrictMode: true, - output: 'export', }; module.exports = nextConfig; diff --git a/pages/[id].jsx b/pages/[id].jsx index c850879..e21ac60 100644 --- a/pages/[id].jsx +++ b/pages/[id].jsx @@ -1,5 +1,4 @@ import Head from 'next/head'; -import apiService from '../services/apiService'; import getFullName from '../util/getFullName'; import getParticipantOrLeaderStatus from '../util/getParticipantOrLeaderStatus'; import { getSkills } from '../util/getSkills'; @@ -15,6 +14,7 @@ import Show from '../components/Show'; import FunFacts from '../components/FunFacts'; import { useFilterContext } from '../context/FilterContext'; import getForecastedHoursIdx from '../util/getForecastedHoursIdx'; +import data from '../mock-data/fellowship.json'; export default function DetailPage({ fetchedTeamMember }) { const cohortStatus = getParticipantOrLeaderStatus(fetchedTeamMember); @@ -28,7 +28,10 @@ export default function DetailPage({ fetchedTeamMember }) { {`${fullName} | Sparkbox Team Availability`} - + - + @@ -64,12 +65,22 @@ export default function DetailPage({ fetchedTeamMember }) { ); } -export async function getServerSideProps({ params, req }) { +export async function getStaticPaths() { + const memberIds = Object.keys(data); + + return { + paths: memberIds.map((id) => ({ + params: { + id, + }, + })), + fallback: false, + }; +} + +export async function getStaticProps({ params }) { const { id } = params; - const { host } = req.headers; - const scheme = process.env.NODE_ENV === 'development' ? 'http://' : 'https://'; - const baseUrl = `${scheme}${host}/api/fellowship/`; - const fetchedTeamMember = await apiService.getTeamMemberById(baseUrl, id); + const fetchedTeamMember = data[id]; if (!fetchedTeamMember) { return { diff --git a/pages/index.jsx b/pages/index.jsx index e7309b6..7d49b7d 100644 --- a/pages/index.jsx +++ b/pages/index.jsx @@ -1,13 +1,11 @@ import Head from 'next/head'; -import apiService from '../services/apiService'; import Filters from '../components/Filters'; import Layout from '../components/Layout'; import CardGrid from '../components/CardGrid'; import WeekSelect from '../components/WeekSelect'; import getUniqueCurrentProjects from '../util/getUniqueCurrentProjects'; import getUniqueRoles from '../util/getUniqueRoles'; - -const scheme = process.env.NODE_ENV === 'development' ? 'http://' : 'https://'; +import data from '../mock-data/fellowship.json'; export default function Home({ teamMembers }) { const uniqueRoles = getUniqueRoles(teamMembers); @@ -29,9 +27,13 @@ export default function Home({ teamMembers }) { ); } -export async function getServerSideProps({ req }) { - const { host } = req.headers; - const teamMembers = await apiService.getAllTeamMembers(`${scheme}${host}/api/fellowship/`); +export async function getStaticProps() { + const teamMembers = Object.keys(data).map((key) => ( + { + id: key, + ...data[key], + } + )); return { props: { From 4865244cda730b86ba371413dce7446f6b19da7d Mon Sep 17 00:00:00 2001 From: dustin-jw Date: Mon, 13 Nov 2023 09:18:20 -0700 Subject: [PATCH 5/5] refactor: use apiService with static paths/props --- __tests__/[id].test.jsx | 68 ++++++++++++++++++------------------- pages/[id].jsx | 8 ++--- pages/index.jsx | 9 ++--- services/apiService.js | 16 +++------ services/apiService.test.js | 6 ++-- 5 files changed, 48 insertions(+), 59 deletions(-) diff --git a/__tests__/[id].test.jsx b/__tests__/[id].test.jsx index 87a7383..cf49314 100644 --- a/__tests__/[id].test.jsx +++ b/__tests__/[id].test.jsx @@ -39,38 +39,38 @@ describe('DetailPage', () => { }); }); -// describe('getStaticProps', () => { -// it('calls getMemberById', async () => { -// const context = { -// params: { -// id: '0001', -// }, -// req: { -// headers: { -// host: 'localhost:3000', -// }, -// }, -// }; -// const response = await getStaticProps(context); +describe('getStaticProps', () => { + it('calls getMemberById', async () => { + const context = { + params: { + id: '0001', + }, + req: { + headers: { + host: 'localhost:3000', + }, + }, + }; + const response = await getStaticProps(context); -// expect(response).toEqual( -// expect.objectContaining({ -// props: { -// fetchedTeamMember: { -// firstName: 'Aragorn', -// lastName: 'Elessar', -// suffix: 'II', -// photo: '/images/mock/aragorn.png', -// currentProjects: [], -// pastProjects: [''], -// funFacts: [], -// weeklyCapacity: 32, -// forecastedHours: [11, 23], -// cohortLeader: 'fellowship', -// cohortParticipant: 'fellowship', -// }, -// }, -// }) -// ); -// }); -// }); + expect(response).toEqual( + expect.objectContaining({ + props: { + fetchedTeamMember: { + firstName: 'Aragorn', + lastName: 'Elessar', + suffix: 'II', + photo: '/images/mock/aragorn.png', + currentProjects: [], + pastProjects: [''], + funFacts: [], + weeklyCapacity: 32, + forecastedHours: [11, 23], + cohortLeader: 'fellowship', + cohortParticipant: 'fellowship', + }, + }, + }) + ); + }); +}); diff --git a/pages/[id].jsx b/pages/[id].jsx index e21ac60..1bf57c9 100644 --- a/pages/[id].jsx +++ b/pages/[id].jsx @@ -1,4 +1,5 @@ import Head from 'next/head'; +import apiService from '../services/apiService'; import getFullName from '../util/getFullName'; import getParticipantOrLeaderStatus from '../util/getParticipantOrLeaderStatus'; import { getSkills } from '../util/getSkills'; @@ -14,7 +15,6 @@ import Show from '../components/Show'; import FunFacts from '../components/FunFacts'; import { useFilterContext } from '../context/FilterContext'; import getForecastedHoursIdx from '../util/getForecastedHoursIdx'; -import data from '../mock-data/fellowship.json'; export default function DetailPage({ fetchedTeamMember }) { const cohortStatus = getParticipantOrLeaderStatus(fetchedTeamMember); @@ -66,10 +66,10 @@ export default function DetailPage({ fetchedTeamMember }) { } export async function getStaticPaths() { - const memberIds = Object.keys(data); + const teamMembers = await apiService.getAllTeamMembers(); return { - paths: memberIds.map((id) => ({ + paths: teamMembers.map(({ id }) => ({ params: { id, }, @@ -80,7 +80,7 @@ export async function getStaticPaths() { export async function getStaticProps({ params }) { const { id } = params; - const fetchedTeamMember = data[id]; + const fetchedTeamMember = await apiService.getTeamMemberById(id); if (!fetchedTeamMember) { return { diff --git a/pages/index.jsx b/pages/index.jsx index 7d49b7d..4c1b8ee 100644 --- a/pages/index.jsx +++ b/pages/index.jsx @@ -1,11 +1,11 @@ import Head from 'next/head'; +import apiService from '../services/apiService'; import Filters from '../components/Filters'; import Layout from '../components/Layout'; import CardGrid from '../components/CardGrid'; import WeekSelect from '../components/WeekSelect'; import getUniqueCurrentProjects from '../util/getUniqueCurrentProjects'; import getUniqueRoles from '../util/getUniqueRoles'; -import data from '../mock-data/fellowship.json'; export default function Home({ teamMembers }) { const uniqueRoles = getUniqueRoles(teamMembers); @@ -28,12 +28,7 @@ export default function Home({ teamMembers }) { } export async function getStaticProps() { - const teamMembers = Object.keys(data).map((key) => ( - { - id: key, - ...data[key], - } - )); + const teamMembers = await apiService.getAllTeamMembers(); return { props: { diff --git a/services/apiService.js b/services/apiService.js index 0168e0c..6dd1197 100644 --- a/services/apiService.js +++ b/services/apiService.js @@ -1,23 +1,17 @@ -const getAllTeamMembers = async (url) => { - const response = await fetch(url); - const data = await response.json(); +import teamMembers from '../mock-data/fellowship.json'; - const dataAsArrayOfObjects = Object.keys(data).map((key) => ( +const getAllTeamMembers = async () => { + const dataAsArrayOfObjects = Object.keys(teamMembers).map((key) => ( { id: key, - ...data[key], + ...teamMembers[key], } )); return dataAsArrayOfObjects; }; -const getTeamMemberById = async (url, identifier) => { - const response = await fetch(url + identifier); - const data = await response.json(); - - return data[identifier]; -}; +const getTeamMemberById = async (identifier) => teamMembers[identifier]; const apiService = { getAllTeamMembers, diff --git a/services/apiService.test.js b/services/apiService.test.js index 57d0d9a..867f3eb 100644 --- a/services/apiService.test.js +++ b/services/apiService.test.js @@ -15,7 +15,7 @@ describe('apiService', () => { }); it('returns team members as an array of objects ', async () => { - const actual = await apiService.getAllTeamMembers('url'); + const actual = await apiService.getAllTeamMembers(); expect(Array.isArray(actual)).toBe(true); }); @@ -40,14 +40,14 @@ describe('apiService', () => { it('returns team member data that matches a given id', async () => { const id = Object.keys(MOCK_DATA)[0]; - const actual = await apiService.getTeamMemberById('url', id); + const actual = await apiService.getTeamMemberById(id); expect(actual).toBe(MOCK_DATA[id]); }); // falsy value is required for [id].jsx 404 page redirect it('returns falsy value if no team member is found', async () => { const id = 'badid'; - const actual = await apiService.getTeamMemberById('url', id); + const actual = await apiService.getTeamMemberById(id); expect(actual).toBeFalsy(); }); });