diff --git a/.env b/.env index e02a63f..cb95f97 100644 --- a/.env +++ b/.env @@ -6,8 +6,8 @@ GITHUB_ID=YOUR_GITHUB_CLIENT_ID GITHUB_SECRET=YOUR_GITHUB_CLIENT_SECRET # Google Auth Provider -GOOGLE_CLIENT_ID=5572607706-p6dftn0ss3m2qnvqbhk4khqte8lk7kt3.apps.googleusercontent.com -GOOGLE_CLIENT_SECRET=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 +GOOGLE_CLIENT_ID=965228443747-049kq59pm43bd23aplfu9ja2333dpo5s.apps.googleusercontent.com +GOOGLE_CLIENT_SECRET=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 DATABASE_URL="postgres://postgres:postgrespwd@localhost:5432/thetiptop" diff --git a/.vscode/settings.json b/.vscode/settings.json index 7a73a41..297b8d0 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,2 +1,7 @@ { + "workbench.colorCustomizations": { + "activityBar.background": "#4C1F25", + "titleBar.activeBackground": "#6A2C34", + "titleBar.activeForeground": "#FEFCFC" + } } \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..1e1196a --- /dev/null +++ b/Dockerfile @@ -0,0 +1,12 @@ +FROM node:alpine + +#copy source +COPY . /app + +# Install deps +RUN cd /app && npm install + +# Build +RUN npm run build + +ENTRYPOINT [ "npm", "run", "start" ] \ No newline at end of file diff --git a/Jenkinsfile b/Jenkinsfile index 4cc9020..b1e1986 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -1,13 +1,41 @@ -pipeline { - agent any - stages { - stage('build') { - steps { - sh '''npm install -npm run build -npm run start''' - } - } - - } -} \ No newline at end of file +rm -rf $WORKSPACE/the_tip_top +git clone git@172.17.0.3:cedric/The_Tip_Top.git $WORKSPACE/the_tip_top + +cd $WORKSPACE/the_tip_top +git checkout master + +yarn install +yarn build + +mkdir the_tip_top + +mv public/ the_tip_top/ + +NEXT_BUILD_ID=$(cat build/BUILD_ID) +LAST_COMMIT=$(git rev-parse HEAD) + +# That's just for debugging purposes +echo "{git: ${LAST_COMMIT}, ci: ${BUILD_ID}, next: ${NEXT_BUILD_ID}}" > the_tip_top/CI + +# trim package.json and leave only things that you need in production +cat package.json | jq '. | {name: .name, private: true, version: .version, scripts: {start: .scripts.start}, dependencies: .dependencies}' > the_tip_top/package.json + +# I'm using next-compose-plugins, so here we need to dump config. If you have next.config.js as an object then just copy config file +NEXT_CONFIG=$(node -e 'var configFile = require("./next.config.js"); var config = configFile([], {}); delete config.webpack; console.log(JSON.stringify(config));') +echo "module.exports = ${NEXT_CONFIG}" > the_tip_top/next.config.js # result => {distDir: "build", poweredByHeader: false} + +mv build the_tip_top/ + +cd the_tip_top + +yarn install + +cd $WORKSPACE/the_tip_top + +# dump folder tree structure just for Jenkins console output logs +tree -h -L 1 build/ + +tar czf $WORKSPACE/the_tip_top.tar.gz the_tip_top +cd $WORKSPACE + +rm -rf $WORKSPACE/the_tip_top diff --git a/README.md b/README.md index a104524..ccbff10 100644 --- a/README.md +++ b/README.md @@ -32,6 +32,9 @@ pour upgrade votre compte en superadmin (vous devez être connecté) http://localhost:3000/api/gain pour générer un gain (vous devez être connecté en tant que superadmin ou admin) +**npm run test** +tests faits avec Playwright + *********************************** diff --git a/package-lock.json b/package-lock.json index 29a3213..5f56962 100644 --- a/package-lock.json +++ b/package-lock.json @@ -16,6 +16,8 @@ "bootstrap": "^5.2.2", "chance": "^1.1.9", "crypto-random-string": "^3.0.0", + "date-format": "^4.0.14", + "dateformat": "^5.0.3", "js-confetti": "^0.11.0", "next": "13.0.2", "next-auth": "4.16.4", @@ -31,6 +33,7 @@ "yup-phone": "^1.3.2" }, "devDependencies": { + "@playwright/test": "^1.28.1", "@types/chance": "^1.1.3", "@types/next-auth": "3.13.0", "@types/node": "18.11.9", @@ -322,6 +325,22 @@ "url": "https://github.com/sponsors/panva" } }, + "node_modules/@playwright/test": { + "version": "1.28.1", + "resolved": "https://registry.npmjs.org/@playwright/test/-/test-1.28.1.tgz", + "integrity": "sha512-xN6spdqrNlwSn9KabIhqfZR7IWjPpFK1835tFNgjrlysaSezuX8PYUwaz38V/yI8TJLG9PkAMEXoHRXYXlpTPQ==", + "dev": true, + "dependencies": { + "@types/node": "*", + "playwright-core": "1.28.1" + }, + "bin": { + "playwright": "cli.js" + }, + "engines": { + "node": ">=14" + } + }, "node_modules/@popperjs/core": { "version": "2.11.6", "resolved": "https://registry.npmjs.org/@popperjs/core/-/core-2.11.6.tgz", @@ -900,6 +919,22 @@ "resolved": "https://registry.npmjs.org/csstype/-/csstype-3.1.1.tgz", "integrity": "sha512-DJR/VvkAvSZW9bTouZue2sSxDwdTN92uHjqeKVm+0dAqdfNykRzQ95tay8aXMBAAPpUiq4Qcug2L7neoRh2Egw==" }, + "node_modules/date-format": { + "version": "4.0.14", + "resolved": "https://registry.npmjs.org/date-format/-/date-format-4.0.14.tgz", + "integrity": "sha512-39BOQLs9ZjKh0/patS9nrT8wc3ioX3/eA/zgbKNopnF2wCqJEoxywwwElATYvRsXdnOxA/OQeQoFZ3rFjVajhg==", + "engines": { + "node": ">=4.0" + } + }, + "node_modules/dateformat": { + "version": "5.0.3", + "resolved": "https://registry.npmjs.org/dateformat/-/dateformat-5.0.3.tgz", + "integrity": "sha512-Kvr6HmPXUMerlLcLF+Pwq3K7apHpYmGDVqrxcDasBg86UcKeTSNWbEzU8bwdXnxnR44FtMhJAxI4Bov6Y/KUfA==", + "engines": { + "node": ">=12.20" + } + }, "node_modules/debug": { "version": "4.3.4", "resolved": "https://registry.npmjs.org/debug/-/debug-4.3.4.tgz", @@ -2600,6 +2635,18 @@ "node": ">=4" } }, + "node_modules/playwright-core": { + "version": "1.28.1", + "resolved": "https://registry.npmjs.org/playwright-core/-/playwright-core-1.28.1.tgz", + "integrity": "sha512-3PixLnGPno0E8rSBJjtwqTwJe3Yw72QwBBBxNoukIj3lEeBNXwbNiKrNuB1oyQgTBw5QHUhNO3SteEtHaMK6ag==", + "dev": true, + "bin": { + "playwright": "cli.js" + }, + "engines": { + "node": ">=14" + } + }, "node_modules/postcss": { "version": "8.4.14", "resolved": "https://registry.npmjs.org/postcss/-/postcss-8.4.14.tgz", @@ -3908,6 +3955,16 @@ "resolved": "https://registry.npmjs.org/@panva/hkdf/-/hkdf-1.0.2.tgz", "integrity": "sha512-MSAs9t3Go7GUkMhpKC44T58DJ5KGk2vBo+h1cqQeqlMfdGkxaVB78ZWpv9gYi/g2fa4sopag9gJsNvS8XGgWJA==" }, + "@playwright/test": { + "version": "1.28.1", + "resolved": "https://registry.npmjs.org/@playwright/test/-/test-1.28.1.tgz", + "integrity": "sha512-xN6spdqrNlwSn9KabIhqfZR7IWjPpFK1835tFNgjrlysaSezuX8PYUwaz38V/yI8TJLG9PkAMEXoHRXYXlpTPQ==", + "dev": true, + "requires": { + "@types/node": "*", + "playwright-core": "1.28.1" + } + }, "@popperjs/core": { "version": "2.11.6", "resolved": "https://registry.npmjs.org/@popperjs/core/-/core-2.11.6.tgz", @@ -4339,6 +4396,16 @@ "resolved": "https://registry.npmjs.org/csstype/-/csstype-3.1.1.tgz", "integrity": "sha512-DJR/VvkAvSZW9bTouZue2sSxDwdTN92uHjqeKVm+0dAqdfNykRzQ95tay8aXMBAAPpUiq4Qcug2L7neoRh2Egw==" }, + "date-format": { + "version": "4.0.14", + "resolved": "https://registry.npmjs.org/date-format/-/date-format-4.0.14.tgz", + "integrity": "sha512-39BOQLs9ZjKh0/patS9nrT8wc3ioX3/eA/zgbKNopnF2wCqJEoxywwwElATYvRsXdnOxA/OQeQoFZ3rFjVajhg==" + }, + "dateformat": { + "version": "5.0.3", + "resolved": "https://registry.npmjs.org/dateformat/-/dateformat-5.0.3.tgz", + "integrity": "sha512-Kvr6HmPXUMerlLcLF+Pwq3K7apHpYmGDVqrxcDasBg86UcKeTSNWbEzU8bwdXnxnR44FtMhJAxI4Bov6Y/KUfA==" + }, "debug": { "version": "4.3.4", "resolved": "https://registry.npmjs.org/debug/-/debug-4.3.4.tgz", @@ -5441,6 +5508,12 @@ "resolved": "https://registry.npmjs.org/pify/-/pify-3.0.0.tgz", "integrity": "sha512-C3FsVNH1udSEX48gGX1xfvwTWfsYWj5U+8/uK15BGzIGrKoUpghX8hWZwa/OFnakBiiVNmBvemTJR5mcy7iPcg==" }, + "playwright-core": { + "version": "1.28.1", + "resolved": "https://registry.npmjs.org/playwright-core/-/playwright-core-1.28.1.tgz", + "integrity": "sha512-3PixLnGPno0E8rSBJjtwqTwJe3Yw72QwBBBxNoukIj3lEeBNXwbNiKrNuB1oyQgTBw5QHUhNO3SteEtHaMK6ag==", + "dev": true + }, "postcss": { "version": "8.4.14", "resolved": "https://registry.npmjs.org/postcss/-/postcss-8.4.14.tgz", diff --git a/package.json b/package.json index 53365ac..dc7a21a 100644 --- a/package.json +++ b/package.json @@ -9,7 +9,8 @@ "dev": "next", "build": "next build", "start": "next start", - "db": "npx prisma migrate reset --force" + "db": "npx prisma migrate reset --force", + "test": "playwright test" }, "dependencies": { "@hookform/resolvers": "^2.9.10", @@ -19,6 +20,8 @@ "bootstrap": "^5.2.2", "chance": "^1.1.9", "crypto-random-string": "^3.0.0", + "date-format": "^4.0.14", + "dateformat": "^5.0.3", "js-confetti": "^0.11.0", "next": "13.0.2", "next-auth": "4.16.4", @@ -34,6 +37,7 @@ "yup-phone": "^1.3.2" }, "devDependencies": { + "@playwright/test": "^1.28.1", "@types/chance": "^1.1.3", "@types/next-auth": "3.13.0", "@types/node": "18.11.9", diff --git a/pages/_fichier_exemple_/api/post/[id].ts b/pages/_fichier_exemple_/api/post/[id].ts deleted file mode 100644 index c25f56c..0000000 --- a/pages/_fichier_exemple_/api/post/[id].ts +++ /dev/null @@ -1,26 +0,0 @@ -import type { NextApiRequest, NextApiResponse } from 'next' -import { getSession } from 'next-auth/react'; -import prisma from '../../../../lib/prisma' - - -// DELETE /api/post/:id -export default async function handle(req: NextApiRequest, res: NextApiResponse) { - const postId = req.query.id; - - const session = await getSession({ req }) - - if (req.method === "DELETE") { - if (session) { - const post = await prisma.post.delete({ - where: { id: Number(postId) }, - }); - res.json(post); - } else { - res.status(401).send({ message: 'Unauthorized' }) - } - } else { - throw new Error( - `The HTTP ${req.method} method is not supported at this route.` - ); - } -} diff --git a/pages/_fichier_exemple_/api/post/index.ts b/pages/_fichier_exemple_/api/post/index.ts deleted file mode 100644 index 3f8b12e..0000000 --- a/pages/_fichier_exemple_/api/post/index.ts +++ /dev/null @@ -1,25 +0,0 @@ -import type { NextApiRequest, NextApiResponse } from 'next' -import prisma from '../../../../lib/prisma' -import { getSession } from 'next-auth/react' - - -// POST /api/post -// Required fields in body: title -// Optional fields in body: content -export default async function handle(req: NextApiRequest, res: NextApiResponse) { - const { title, content } = req.body; - - const session = await getSession({ req }); - if (session) { - const result = await prisma.post.create({ - data: { - title: title, - content: content, - author: { connect: { email: session?.user?.email } }, - }, - }); - res.json(result); - } else { - res.status(401).send({ message: 'Unauthorized' }) - } -} diff --git a/pages/_fichier_exemple_/api/profile/index.ts b/pages/_fichier_exemple_/api/profile/index.ts deleted file mode 100644 index 2d03ede..0000000 --- a/pages/_fichier_exemple_/api/profile/index.ts +++ /dev/null @@ -1,34 +0,0 @@ -import type { NextApiRequest, NextApiResponse } from 'next' -import prisma from '../../../../lib/prisma' -import { getSession } from 'next-auth/react' - - -// UPDATE /api/profile -// Required fields in body: title -export default async function handle(req: NextApiRequest, res: NextApiResponse) { - const { bioValue } = req.body; - console.log('server biovalue:', bioValue) - const session = await getSession({ req }); - - if (req.method === "PUT") { - if (session) { - const updateUserProfil = await prisma.user.update({ - where: { email: session.user.email }, - data: { - profile: { - update: { - bio: bioValue, - }, - }, - } - }) - res.status(200).send({ result: updateUserProfil, message: 'Profiled updated !' }); - } else { - res.status(401).send({ message: 'Unauthorized' }) - } - } else { - throw new Error( - `The HTTP ${req.method} method is not supported at this route.` - ); - } -} \ No newline at end of file diff --git a/pages/_fichier_exemple_/api/publish/[id].ts b/pages/_fichier_exemple_/api/publish/[id].ts deleted file mode 100644 index 3d1f064..0000000 --- a/pages/_fichier_exemple_/api/publish/[id].ts +++ /dev/null @@ -1,19 +0,0 @@ -import type { NextApiRequest, NextApiResponse } from 'next' -import { getSession } from 'next-auth/react'; -import prisma from '../../../../lib/prisma' - -// PUT /api/publish/:id -export default async function handle(req: NextApiRequest, res: NextApiResponse) { - const postId = req.query.id; - const session = await getSession({ req }) - - if (session) { - const post = await prisma.post.update({ - where: { id: Number(postId) }, - data: { published: true }, - }); - res.json(post); - } else { - res.status(401).send({ message: 'Unauthorized' }) - } -} diff --git a/pages/_fichier_exemple_/create.tsx b/pages/_fichier_exemple_/create.tsx deleted file mode 100644 index d9f8b1a..0000000 --- a/pages/_fichier_exemple_/create.tsx +++ /dev/null @@ -1,81 +0,0 @@ -import React, { useState } from "react"; -import Layout from "../../components/Layout"; -import Router from "next/router"; - -const Draft = () => { - const [title, setTitle] = useState(""); - const [content, setContent] = useState(""); - - const submitData = async (e: React.SyntheticEvent) => { - e.preventDefault(); - try { - const body = { title, content }; - await fetch(`/api/post`, { - method: "POST", - headers: { "Content-Type": "application/json" }, - body: JSON.stringify(body), - }); - await Router.push("/drafts"); - } catch (error) { - console.error(error); - } - }; - - return ( - -
-
-

New Draft

- setTitle(e.target.value)} - placeholder="Title" - type="text" - value={title} - /> -