Skip to content

Commit

Permalink
Release v0.2.0 (#191)
Browse files Browse the repository at this point in the history
  • Loading branch information
shashilo authored May 2, 2024
2 parents 64000c2 + e74dbfe commit 61e2997
Show file tree
Hide file tree
Showing 76 changed files with 5,322 additions and 22,444 deletions.
10 changes: 10 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"parser": "@typescript-eslint/parser",
"plugins": ["@typescript-eslint"],
"extends": [
"plugin:jsx-a11y/recommended",
"next/core-web-vitals",
"plugin:@typescript-eslint/eslint-recommended",
"plugin:@typescript-eslint/recommended"
]
}
26 changes: 25 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ jobs:
push: true
tags: ghcr.io/letsgettechnical/image:dev
#A workflow is for testing
tests:
jest-test:
runs-on: ubuntu-latest

strategy:
Expand All @@ -48,3 +48,27 @@ jobs:
run: pnpm install
- name: tests
run: pnpm test
#Playwright Testing
playwright-test:
timeout-minutes: 60000
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: lts/*
- name: Install dependencies
run: npm install -g pnpm && pnpm install
- name: Install Playwright Browsers
run: pnpm exec playwright install --with-deps
- name: Run Playwright tests
run: pnpm exec playwright test
- uses: actions/upload-artifact@v4
if: always()
with:
name: playwright-report
path: playwright-report/
retention-days: 30


12 changes: 11 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.

# dependencies
/functions/node_modules
/node_modules
/.pnp
.pnp.js
Expand Down Expand Up @@ -35,4 +36,13 @@ yarn-error.log*
*.tsbuildinfo
next-env.d.ts

*storybook.log
#playwright
/blob-report/
/playwright/.cache/

*storybook.log
/blob-report/
/playwright/.cache/
storybook-static/*

.vscode
5 changes: 5 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
.github/
*.config.js
.prettierrc.js
*.md
settings.json
21 changes: 11 additions & 10 deletions .storybook/main.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,24 @@
import type { StorybookConfig } from "@storybook/nextjs";
import type { StorybookConfig } from '@storybook/nextjs';

const config: StorybookConfig = {
stories: [
"../stories/**/*.mdx",
"../stories/**/*.stories.@(js|jsx|mjs|ts|tsx)",
'../stories/**/*.mdx',
'../components/**/*.stories.@(js|jsx|mjs|ts|tsx)',
],
staticDirs: ['../public'],
addons: [
"@storybook/addon-onboarding",
"@storybook/addon-links",
"@storybook/addon-essentials",
"@chromatic-com/storybook",
"@storybook/addon-interactions",
'@storybook/addon-onboarding',
'@storybook/addon-links',
'@storybook/addon-essentials',
'@chromatic-com/storybook',
'@storybook/addon-interactions',
],
framework: {
name: "@storybook/nextjs",
name: '@storybook/nextjs',
options: {},
},
docs: {
autodocs: "tag",
autodocs: 'tag',
},
};
export default config;
11 changes: 9 additions & 2 deletions .storybook/preview.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { Preview } from "@storybook/react";
import "../app/globals.css";
import type { Preview } from '@storybook/react';
import '../app/globals.css';

const preview: Preview = {
parameters: {
Expand All @@ -9,6 +9,13 @@ const preview: Preview = {
date: /Date$/i,
},
},
backgrounds: {
default: 'dark',
values: [
{ name: 'dark', value: '#09090B' },
{ name: 'light', value: '#fff' },
],
},
},
};

Expand Down
2 changes: 1 addition & 1 deletion CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
# 👴Senior devs. Each PR requires at least 1 senior review before merging.
* @shashilo @mhchen @jayrobin
* @shashilo @mhchen
39 changes: 39 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -103,3 +103,42 @@ Run Storybook in the project root
```
npm run storybook
```

## React Testing Library (RTL) && Jest

Run RTL && Jest in the project root

```
pnpm test
```

## Playwright Testing


Run all Playwright tests

```
pnpm exec playwright test
```

Run single Playwright tests

```
pnpm exec playwright test (name of file)
```
## Prettier

Search for and open `settings.json` by pressing `cmd+shift+p` on MacOS or `ctrl+shift+p` on Windows.

> [!IMPORTANT]
> There may be multiple options, ensure you select the option that says "Open User Settings (JSON)
![Screenshot of VS Code search results for "settings.json" with the User Settings JSON option highlighted.](https://res.cloudinary.com/ryan-furrer/image/upload/v1712793797/Vscode_settings.json_wuoqgc.png)

Add the following lines to your `settings.json`

```
"editor.defaultFormatter": "esbenp.prettier-vscode",
"editor.formatOnSave": true,
```

Open a file and save it, you should see formatting changes made as soon as you save it!
114 changes: 114 additions & 0 deletions api/apiFunctions.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
import { loginAccount, logoutAccount, registerAccount } from './apiFunctions';
import { account } from './config';
const apiFunctions = require("./apiFunctions");

jest.mock("./apiFunctions", ()=> {
const actualModule = jest.requireActual("./apiFunctions");
return {
...actualModule,
createWeeklyPicks: jest.fn(),
getUserWeeklyPick: jest.fn()
}
})

describe('Auth Functions', () => {
jest.mock('./apiFunctions', () => ({
loginAccount: jest.fn(),
registerAccount: jest.fn(),
}));

xdescribe('login account successful', () => {
it('should show user login successfully', async () => {
const userDummy = {
email: '[email protected]',
password: 'test1234',
};
await loginAccount(userDummy);
expect(account.createEmailPasswordSession).toBeInstanceOf(Object);
});

//user failed to log in
it('should send error if user could not log in', async () => {
const failDummy = {
email: '[email protected]',
password: 'tet1234679',
};
await loginAccount(failDummy);
expect(loginAccount(failDummy)).rejects.toThrow('error');
});
});

// Test the logout function
describe('logout account works', () => {
it('should log out successfully', async () => {
jest
.spyOn(account, 'deleteSession')
.mockResolvedValueOnce('Session deleted');
await logoutAccount();
expect(account.deleteSession).toHaveBeenCalledTimes(1);
});
});

account.create = jest.fn();
describe('register account successful', () => {
it('Should allow a user to register an account', async () => {
const userDummy = {
email: '[email protected]',
password: 'test12345',
};
const response = await registerAccount(userDummy);
expect(account.create).toHaveBeenCalledWith(
expect.any(String),
userDummy.email,
userDummy.password,
);
});
});
});

xtest('get weekly picks mock function', async () => {
const users = { userId: '66174f2362ec891167be' };
const resp = { data: users };

// Mocking the getWeeklyPicks function
jest.mock('./apiFunctions', () => ({
getUserWeeklyPick: jest.fn().mockResolvedValue(resp),
}));

// Importing the mocked function
const { getUserWeeklyPick: mockGetUserWeeklyPick } = require('./apiFunctions');

// Call the function
const result = await mockGetUserWeeklyPick();

// Assertions
expect(result).toEqual(resp); // Check if the result matches the expected response
});


describe("Get Weekly Picks Mock function", () => {
it('should mock getWeeklyPicks function', async () => {
const users = {$id: '663130a100297f77c3c8' };
const resp = { data: users };

apiFunctions.getUserWeeklyPick.mockResolvedValue(resp);

const result = await apiFunctions.getUserWeeklyPick({userId: '66281d5ec5614f76bc91', weekNumber: "6622c75658b8df4c4612"});

expect(result).toEqual(resp);
});
});

describe("Create Weekly Picks Mock Function", () => {
it("should mock createWeeklyPicks function", async () => {
const users = { team: '66218f22b40deef340f8', correct: false };
const resp = {data: users};

apiFunctions.createWeeklyPicks.mockResolvedValue(resp);

const result = await apiFunctions.createWeeklyPicks({gameWeekId: "6622c7596558b090872b",gameId: "66311a210039f0532044", userResults: "{\"66281d5ec5614f76bc91\":{\"team\":\"66218f22b40deef340f8\",\"correct\":false},\"6628077faeeedd272637\":{\"team\":\"6621b30ea57bd075e9d3\",\"correct\":false}, \"66174f2362ec891167be\":{\"team\": \"6621b30ea57bd075e9d3\", \"correct\":true}}"});

expect(result).toEqual(resp);

})
})
85 changes: 85 additions & 0 deletions api/apiFunctions.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
import { account, databases, ID, appwriteConfig } from './config';

export async function loginAccount(user: { email: string; password: string }) {
try {
return await account.createEmailPasswordSession(user.email, user.password);
} catch (error) {
console.error(error);
}
}

export async function logoutAccount() {
try {
return await account.deleteSession('current');
} catch (error) {
console.error(error);
}
}

export async function getUserWeeklyPick(data: {
userId: string;
weekNumber: string;
}) {
try {
const response = await databases.listDocuments(
appwriteConfig.databaseId,
'66313025000612a5380e',
);
return response.documents[0].userResults;
} catch (error) {
console.error(error);
}
}

export async function getAllWeeklyPicks() {
try {
const response = await databases.listDocuments(
appwriteConfig.databaseId,
'66313025000612a5380e',
);
return response;
} catch (error) {
console.error(error);
}
}

export async function getNFLTeams() {
try {
return await databases.listDocuments(
appwriteConfig.databaseId,
'662152bfabacfbda3bb3',
);
} catch (error) {
console.error(error);
}
}

export async function registerAccount(request: {
email: string;
password: string;
}) {
const { email, password } = request;

try {
return await account.create(ID.unique(), email, password);
} catch (error: any) {
throw error;
}
}

export async function createWeeklyPicks(data: {
gameId: string;
gameWeekId: string;
userResults: string;
}) {
try {
return await databases.updateDocument(
appwriteConfig.databaseId,
'66313025000612a5380e',
'663130a100297f77c3c8',
data,
);
} catch (error) {
console.error(error);
}
}
Loading

1 comment on commit 61e2997

@vercel
Copy link

@vercel vercel bot commented on 61e2997 May 2, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.