Skip to content

Commit

Permalink
fix: ci
Browse files Browse the repository at this point in the history
  • Loading branch information
vincentchalamon committed Aug 30, 2023
1 parent b0cf130 commit c42bdba
Show file tree
Hide file tree
Showing 29 changed files with 360 additions and 133 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@ jobs:
POSTGRES_PASSWORD: aae5bf316ef5fe87ad806c6a9240fff68bcfdaf7
KEYCLOAK_POSTGRES_PASSWORD: 26d7f630f1524eb210bbf496443f2038a9316e9e
KEYCLOAK_ADMIN_PASSWORD: 2f31e2fad93941b818449fd8d57fd019b6ce7fa5
KEYCLOAK_HTTPS_CERTIFICATE_FILE: ./helm/api-platform/keycloak/certs/tls.crt
KEYCLOAK_HTTPS_CERTIFICATE_KEY_FILE: ./helm/api-platform/keycloak/certs/tls.pem
# https://docs.docker.com/compose/environment-variables/envvars/
COMPOSE_FILE: docker-compose.yml:docker-compose.prod.yml
steps:
Expand Down
14 changes: 3 additions & 11 deletions api/src/DataFixtures/Story/DefaultStory.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
use App\DataFixtures\Factory\ReviewFactory;
use App\DataFixtures\Factory\UserFactory;
use App\Enum\BookCondition;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Serializer\Encoder\DecoderInterface;
use Zenstruck\Foundry\Story;

Expand All @@ -24,7 +23,7 @@ public function build(): void
// Create default book (must be created first to appear first in list)
$defaultBook = BookFactory::createOne([
'condition' => BookCondition::UsedCondition,
'book' => 'https://openlibrary.org/books/OL17267881W.json',
'book' => 'https://openlibrary.org/books/OL25840917M.json',
'title' => 'The Three-Body Problem',
'author' => 'Liu Cixin',
]);
Expand Down Expand Up @@ -75,13 +74,15 @@ public function build(): void
BookmarkFactory::createOne([
'book' => $defaultBook,
'user' => $defaultUser,
'bookmarkedAt' => \DateTimeImmutable::createFromMutable(BookmarkFactory::faker()->dateTime('-1 hour')),
]);

// Default user has bookmarked other books
foreach (array_rand($books, 30) as $key) {
BookmarkFactory::createOne([
'user' => $defaultUser,
'book' => $books[$key],
'bookmarkedAt' => \DateTimeImmutable::createFromMutable(BookmarkFactory::faker()->dateTime('-1 week')),
]);
}

Expand All @@ -93,13 +94,4 @@ public function build(): void
'roles' => ['ROLE_ADMIN'],
]);
}

private function getData(string $uri): array
{
return $this->decoder->decode($this->client->request(Request::METHOD_GET, $uri, [
'headers' => [
'Accept' => 'application/json',
],
])->getContent(), 'json');
}
}
2 changes: 1 addition & 1 deletion api/src/Entity/Book.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ class Book
*/
#[ApiProperty(
types: ['https://schema.org/itemOffered', 'https://purl.org/dc/terms/BibliographicResource'],
example: 'https://openlibrary.org/books/OL17267881W.json'
example: 'https://openlibrary.org/books/OL25840917M.json'
)]
#[Assert\NotBlank(allowNull: false)]
#[Assert\Url(protocols: ['https'])]
Expand Down
1 change: 1 addition & 0 deletions api/src/Entity/Bookmark.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
*/
#[ApiResource(
types: ['https://schema.org/BookmarkAction'],
order: ['bookmarkedAt' => 'ASC'],
operations: [
new GetCollection(),
new Delete(
Expand Down
6 changes: 3 additions & 3 deletions api/tests/Api/BookmarkTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public function testAsAUserICanGetACollectionOfMyBookmarksWithoutFilters(): void

public function testAsAnonymousICannotCreateABookmark(): void
{
$book = BookFactory::createOne(['book' => 'https://openlibrary.org/books/OL17267881W.json']);
$book = BookFactory::createOne(['book' => 'https://openlibrary.org/books/OL25840917M.json']);

$this->client->request('POST', '/bookmarks', [
'json' => [
Expand Down Expand Up @@ -123,7 +123,7 @@ public function testAsAUserICannotCreateABookmarkWithInvalidData(): void
*/
public function testAsAUserICanCreateABookmark(): void
{
$book = BookFactory::createOne(['book' => 'https://openlibrary.org/books/OL17267881W.json']);
$book = BookFactory::createOne(['book' => 'https://openlibrary.org/books/OL25840917M.json']);
$user = UserFactory::createOne();
self::getMercureHub()->reset();

Expand Down Expand Up @@ -164,7 +164,7 @@ public function testAsAUserICanCreateABookmark(): void

public function testAsAUserICannotCreateADuplicateBookmark(): void
{
$book = BookFactory::createOne(['book' => 'https://openlibrary.org/books/OL17267881W.json']);
$book = BookFactory::createOne(['book' => 'https://openlibrary.org/books/OL25840917M.json']);
$user = UserFactory::createOne();
BookmarkFactory::createOne(['book' => $book, 'user' => $user]);
self::getMercureHub()->reset();
Expand Down
4 changes: 2 additions & 2 deletions api/tests/Serializer/BookNormalizerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public function testItNormalizesData(): void
->method('normalize')
->with($expectedObject, null, [BookNormalizer::class => true])
->willReturn([
'book' => 'https://openlibrary.org/books/OL17267881W.json',
'book' => 'https://openlibrary.org/books/OL25840917M.json',
'title' => 'Foundation',
'author' => 'Liu Cixin',
'condition' => BookCondition::NewCondition->value,
Expand All @@ -82,7 +82,7 @@ public function testItNormalizesData(): void
]);

$this->assertEquals([
'book' => 'https://openlibrary.org/books/OL17267881W.json',
'book' => 'https://openlibrary.org/books/OL25840917M.json',
'title' => 'Foundation',
'author' => 'Liu Cixin',
'condition' => BookCondition::NewCondition->value,
Expand Down
4 changes: 2 additions & 2 deletions api/tests/State/Processor/BookPersistProcessorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ protected function setUp(): void
$this->responseMock = $this->createMock(ResponseInterface::class);
$this->decoderMock = $this->createMock(DecoderInterface::class);
$this->objectMock = $this->createMock(Book::class);
$this->objectMock->book = 'https://openlibrary.org/books/OL17267881W.json';
$this->objectMock->book = 'https://openlibrary.org/books/OL25840917M.json';
$this->operationMock = $this->createMock(Operation::class);

$this->processor = new BookPersistProcessor(
Expand All @@ -56,7 +56,7 @@ public function testItUpdatesBookDataBeforeSaveAndSendMercureUpdates(): void
->method('request')
->withConsecutive(
[
Request::METHOD_GET, 'https://openlibrary.org/books/OL17267881W.json', [
Request::METHOD_GET, 'https://openlibrary.org/books/OL25840917M.json', [
'headers' => [
'Accept' => 'application/json',
],
Expand Down
8 changes: 7 additions & 1 deletion docker-compose.prod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,5 +47,11 @@ services:
keycloak:
environment:
KEYCLOAK_PRODUCTION: "true"
KEYCLOAK_ENABLE_HTTPS: "false"
KEYCLOAK_ADMIN_PASSWORD: ${KEYCLOAK_ADMIN_PASSWORD}
KEYCLOAK_ENABLE_HTTPS: "true"
KEYCLOAK_HTTPS_USE_PEM: "true"
KEYCLOAK_HTTPS_CERTIFICATE_FILE: /opt/bitnami/keycloak/certs/tls.crt
KEYCLOAK_HTTPS_CERTIFICATE_KEY_FILE: /opt/bitnami/keycloak/certs/tls.key
volumes:
- ${KEYCLOAK_HTTPS_CERTIFICATE_FILE}:/opt/bitnami/keycloak/certs/tls.crt:ro
- ${KEYCLOAK_HTTPS_CERTIFICATE_KEY_FILE}:/opt/bitnami/keycloak/certs/tls.key:ro
21 changes: 21 additions & 0 deletions helm/api-platform/keycloak/certs/tls.crt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
-----BEGIN CERTIFICATE-----
MIIDazCCAlOgAwIBAgIUGiIkdQOTG1A7NvXDLig7TVDsymIwDQYJKoZIhvcNAQEL
BQAwRTELMAkGA1UEBhMCQVUxEzARBgNVBAgMClNvbWUtU3RhdGUxITAfBgNVBAoM
GEludGVybmV0IFdpZGdpdHMgUHR5IEx0ZDAeFw0yMzA4MjcxNjM5NTFaFw0yNDA4
MjYxNjM5NTFaMEUxCzAJBgNVBAYTAkFVMRMwEQYDVQQIDApTb21lLVN0YXRlMSEw
HwYDVQQKDBhJbnRlcm5ldCBXaWRnaXRzIFB0eSBMdGQwggEiMA0GCSqGSIb3DQEB
AQUAA4IBDwAwggEKAoIBAQCvnrhtub8e1nwpRj7a0MDDnlH77BzANSVHLR54kB0x
H4wFCIn7GIRXZsKr4xOH68obhtAFbXu+U6fK6ZkmHqhTtro/nU6eGGZhFK6eSVsg
4Hp07eoQ7oNsRX33nScZfpWo6YnH0yFwiUFM8oQW5rNBOUlJfwVONnPQcdGN6X6o
lmuG2j0devmlKoohoIR/P/TNU/4X+PSvotjt1TyPFOeTWPwYvuOoYMiSFQSFNoRy
c67N4Np88PGL84zl9FjZO9ndGje/CDgm3FJj7gswetNX7+4Ge3Q0121vfsvZ2M6k
GTX6jwEysSyvbI0ewjX04IwuWjz1nXYgc4+XbC7N7pmdAgMBAAGjUzBRMB0GA1Ud
DgQWBBT2Hy1/xksuYgSTATWa/O6aD39wvDAfBgNVHSMEGDAWgBT2Hy1/xksuYgST
ATWa/O6aD39wvDAPBgNVHRMBAf8EBTADAQH/MA0GCSqGSIb3DQEBCwUAA4IBAQBF
RDCteKuQ+RTEyzsAzslbPm+S/4T8bI+51Xuy+2ehidJtp0RXBk1VIcG2qG3rQdJF
eTe4QbRZPC2g1CjnbBLkoMDJuGCY9a7b1Bc7pCS8oAfN5V044Uem7ydJuekoMEAR
br95hojGe8RN/YOjOa/U9TazjCTo5JFi1UWg+WKK/r8YrBJJWsU+ORxCNMOaVgFp
286Gqdn+4aQo6bPx3xV0X/ny7Dq5i6FpvQkFopUcNpRUnYg+VpB01mNO6BsuduuG
3nmnDCo77LIOVvBuoRpRLaXsqDc7JbLeE1B9lRp1mbvPhTaDXotUglUIaASegA/d
JwdqphZXvvEVMCufLfoY
-----END CERTIFICATE-----
49 changes: 49 additions & 0 deletions helm/api-platform/keycloak/certs/tls.pem
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
-----BEGIN PRIVATE KEY-----
MIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwggSkAgEAAoIBAQCvnrhtub8e1nwp
Rj7a0MDDnlH77BzANSVHLR54kB0xH4wFCIn7GIRXZsKr4xOH68obhtAFbXu+U6fK
6ZkmHqhTtro/nU6eGGZhFK6eSVsg4Hp07eoQ7oNsRX33nScZfpWo6YnH0yFwi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ewjX04IwuWjz1nXYgc4+XbC7N7pmdAgMBAAGjUzBRMB0GA1Ud
DgQWBBT2Hy1/xksuYgSTATWa/O6aD39wvDAfBgNVHSMEGDAWgBT2Hy1/xksuYgST
ATWa/O6aD39wvDAPBgNVHRMBAf8EBTADAQH/MA0GCSqGSIb3DQEBCwUAA4IBAQBF
RDCteKuQ+RTEyzsAzslbPm+S/4T8bI+51Xuy+2ehidJtp0RXBk1VIcG2qG3rQdJF
eTe4QbRZPC2g1CjnbBLkoMDJuGCY9a7b1Bc7pCS8oAfN5V044Uem7ydJuekoMEAR
br95hojGe8RN/YOjOa/U9TazjCTo5JFi1UWg+WKK/r8YrBJJWsU+ORxCNMOaVgFp
286Gqdn+4aQo6bPx3xV0X/ny7Dq5i6FpvQkFopUcNpRUnYg+VpB01mNO6BsuduuG
3nmnDCo77LIOVvBuoRpRLaXsqDc7JbLeE1B9lRp1mbvPhTaDXotUglUIaASegA/d
JwdqphZXvvEVMCufLfoY
-----END CERTIFICATE-----
16 changes: 8 additions & 8 deletions pwa/components/book/Filters.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { Formik } from "formik";
import { type FunctionComponent } from "react";
import { type UseMutationResult } from "react-query";
import { debounce, Checkbox, FormControlLabel, FormGroup, TextField, Typography } from "@mui/material";
import {Formik} from "formik";
import {type FunctionComponent} from "react";
import {type UseMutationResult} from "react-query";
import {Checkbox, debounce, FormControlLabel, FormGroup, TextField, Typography} from "@mui/material";

import { type FiltersProps } from "@/utils/book";
import { type FetchError, type FetchResponse } from "@/utils/dataAccess";
import { type PagedCollection } from "@/types/collection";
import { type Book } from "@/types/Book";
import {type FiltersProps} from "@/utils/book";
import {type FetchError, type FetchResponse} from "@/utils/dataAccess";
import {type PagedCollection} from "@/types/collection";
import {type Book} from "@/types/Book";

interface Props {
filters: FiltersProps | undefined;
Expand Down
7 changes: 4 additions & 3 deletions pwa/components/book/List.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import Head from "next/head";
import { useRouter } from "next/router";
import { useMutation } from "react-query";
import FilterListOutlinedIcon from "@mui/icons-material/FilterListOutlined";
import { FormControl, InputLabel, MenuItem, Select } from "@mui/material";
import { MenuItem, Select } from "@mui/material";

import { Item } from "@/components/book/Item";
import { Filters } from "@/components/book/Filters";
Expand All @@ -18,11 +18,12 @@ interface Props {
data: PagedCollection<Book> | null;
hubURL: string | null;
filters: FiltersProps;
page: number;
}

const getPagePath = (page: number): string => `/books?page=${page}`;

export const List: NextPage<Props> = ({ data, hubURL, filters }) => {
export const List: NextPage<Props> = ({ data, hubURL, filters, page }) => {
const collection = useMercure(data, hubURL);
const router = useRouter();

Expand Down Expand Up @@ -76,7 +77,7 @@ export const List: NextPage<Props> = ({ data, hubURL, filters }) => {
<Item key={book["@id"]} book={book}/>
))}
</div>
<Pagination collection={collection} getPagePath={getPagePath} currentPage={filters?.page}/>
<Pagination collection={collection} getPagePath={getPagePath} currentPage={page}/>
</>
) || (
<p className="w-full flex px-8 pb-4 text-lg">No books found.</p>
Expand Down
20 changes: 14 additions & 6 deletions pwa/components/book/Show.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,18 +50,26 @@ export const Show: NextPage<Props> = ({ data, hubURL, page }) => {
Error | FetchError,
BookmarkProps
// @ts-ignore
>((data: BookmarkProps) => {
>(async (data: BookmarkProps) => {
// @ts-ignore
if (!session || session?.error === "RefreshAccessTokenError") return signIn("keycloak");

// @ts-ignore
if (bookmark) return deleteBookmark(bookmark["@id"]);
if (bookmark) {
// @ts-ignore
deleteBookmark(bookmark["@id"]);
setBookmark(undefined);

return;
}

return saveBookmark(data);
const response: FetchResponse<Bookmark> | undefined = await saveBookmark(data);
if (response && response?.data) {
setBookmark(response.data);
}
});

useEffect(() => {
if (status === "loading") return;
if (status === "loading" || status === "unauthenticated") return;

(async () => {
try {
Expand Down Expand Up @@ -126,7 +134,7 @@ export const Show: NextPage<Props> = ({ data, hubURL, page }) => {
{book["description"] ?? "This book has no description."}
</p>
<button className="mt-4 px-10 py-4 font-semibold text-sm bg-cyan-500 text-white rounded-full shadow-sm"
onClick={() => bookmarkMutation.mutate({ book: book["@id"] })}>
onClick={() => bookmarkMutation.mutate({ book: book["@id"] })} data-testid="bookmark">
{!!bookmark && (
<>
<FavoriteIcon className="w-6 h-6 mr-2"/>
Expand Down
2 changes: 1 addition & 1 deletion pwa/components/common/Pagination.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { parsePage } from "@/utils/dataAccess";
interface Props {
collection: PagedCollection<unknown>;
getPagePath: (page: number) => string;
currentPage: number | undefined;
currentPage: number;
}

export const Pagination = ({ collection, getPagePath, currentPage }: Props) => {
Expand Down
4 changes: 2 additions & 2 deletions pwa/components/review/List.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { type FunctionComponent, useEffect, useState } from "react";
import {signIn, useSession} from "next-auth/react";
import { signIn, useSession } from "next-auth/react";

import { Pagination } from "@/components/common/Pagination";
import { type Book } from "@/types/Book";
Expand Down Expand Up @@ -78,7 +78,7 @@ export const List: FunctionComponent<Props> = ({ book, page }) => {
{collection["hydra:member"].map((review) => (
<Item key={review["@id"]} review={review} onDelete={() => setData(undefined)}/>
))}
<Pagination collection={collection} getPagePath={getPagePath} currentPage={page ? Number(page) : 1}/>
<Pagination collection={collection} getPagePath={getPagePath} currentPage={page}/>
</>
) || !!collection && (
<p className="text-gray-600">Be the first to add a review!</p>
Expand Down
4 changes: 2 additions & 2 deletions pwa/pages/bookmarks/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,12 @@ export const getServerSideProps: GetServerSideProps<{
throw new Error('Unable to retrieve data from /bookmarks.');
}

return { props: { data: response.data, hubURL: response.hubURL, page: page ?? 1 } };
return { props: { data: response.data, hubURL: response.hubURL, page: Number(page ?? 1) } };
} catch (error) {
console.error(error);
}

return { props: { data: null, hubURL: null, page: page ?? 1 } };
return { props: { data: null, hubURL: null, page: Number(page ?? 1) } };
};

export default List;
2 changes: 1 addition & 1 deletion pwa/pages/books/[id]/[slug]/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export const getServerSideProps: GetServerSideProps<{
throw new Error(`Unable to retrieve data from /books/${id}.`);
}

return { props: { data: response.data, hubURL: response.hubURL, page: page ? Number(page) : 1 } };
return { props: { data: response.data, hubURL: response.hubURL, page: Number(page ?? 1) } };
} catch (error) {
console.error(error);
}
Expand Down
7 changes: 4 additions & 3 deletions pwa/pages/books/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,11 @@ export const getServerSideProps: GetServerSideProps<{
hubURL: string | null,
filters: FiltersProps,
}> = async ({ query }) => {
const page = Number(query.page ?? 1);
const filters: FiltersProps = {};
if (query.page) {
// @ts-ignore
filters.page = Number(query.page);
filters.page = query.page;
}
if (query.author) {
// @ts-ignore
Expand Down Expand Up @@ -43,12 +44,12 @@ export const getServerSideProps: GetServerSideProps<{
throw new Error('Unable to retrieve data from /books.');
}

return { props: { data: response.data, hubURL: response.hubURL, filters } };
return { props: { data: response.data, hubURL: response.hubURL, filters, page } };
} catch (error) {
console.error(error);
}

return { props: { data: null, hubURL: null, filters } };
return { props: { data: null, hubURL: null, filters, page } };
};

export default List;
Loading

0 comments on commit c42bdba

Please sign in to comment.