Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Postgres Migration Support for Plugins and Plugin store in orgDashboard #3745

Closed
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
202 changes: 103 additions & 99 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ If you are new to contributing to open source, please read the Open Source Guide
- [Pull Requests](#pull-requests)
- [Branching Strategy](#branching-strategy)
- [Conflict Resolution](#conflict-resolution)
- [Contributing Code](#contributing-code)
- [General:](#general)
- [Testing:](#testing)
- [Jest Testing](#jest-testing)
Expand Down Expand Up @@ -69,7 +68,7 @@ Make sure you are following [issue report guidelines](ISSUE_GUIDELINES.md) avail

#### Branching Strategy

For Talawa Admin, we had employed the following branching strategy to simplify the development process and to ensure that only stable code is pushed to the `main` branch:
For Talawa Admin, we had employed the following branching strategy to simplify the development process and to ensure that only stable code is pushed to the `master` branch:

- `develop`: For unstable code and bug fixing
- `main`: Where the stable production ready code lies. This is our default branch.
Expand All @@ -83,8 +82,6 @@ When multiple developers are working on issues there is bound to be a conflict o
- Last but not the least, communication is important make sure to talk to other contributors, in these cases, in slack channel or in a issue/PR thread.
- As a last resort the Admins would be responsible for deciding how to resolve this conflict.

### Contributing Code

Code contributions to Talawa come in the form of pull requests. These are done by forking the repo and making changes locally.

Make sure you have read the [Documentation for Setting up the Project](https://github.com/PalisadoesFoundation/talawa-admin#project-setup)
Expand All @@ -100,105 +97,112 @@ The process of proposing a change to Talawa Admin can be summarized as:

### General:

- We need to get to 100% test coverage for the app. We periodically increase the desired test coverage for our pull requests to meet this goal.
- Pull requests that don't meet the minimum test coverage levels will not be accepted. This may mean that you will have to create tests for code you did not write. You can decide which part of the code base needs additional tests if this happens to you.
- We need to get to 100% test coverage for the app. We periodically increase the desired test coverage for our pull requests to meet this goal.
- Pull requests that don't meet the minimum test coverage levels will not be accepted. This may mean that you will have to create tests for code you did not write. You can decide which part of the code base needs additional tests if this happens to you.

### Testing:

This section outlines the different testing strategies and tools used in this project. It includes instructions on running tests, viewing code coverage, and debugging using Jest and Vitest. Following these guidelines ensures code reliability and maintains the project's high standards for quality.
#### Jest Testing
- Running a single test:
```
npm run test path/to/test/file
```
- Running all tests:
```
npm run test --watchAll=false
```
- Viewing the code coverage of a single test file:
```
npm run test --watchAll=false --coverage /path/to/test/file
```
- Viewing the code coverage of all test files:
```
npm run test --watchAll=false --coverage
```
- Debug tests in browser
You can see the output of failing tests in broswer by running `jest-preview` package before running your tests
```
npm run jest-preview
npm run test --watchAll=false --coverage
```
You don't need to re-run the `npm run jest-preview` command each time, simply run the `npm run test` command if the Jest Preview server is already running in the background, it'll automatically detect any failing tests and show the preview at `http://localhost:3336` as shown in this screenshot -

![Debugging Test Demo](./public/images/jest-preview.webp)
#### Vitest Testing
- Running a single test:
```
npm run test:vitest /path/to/test/file
```
- Running all tests:
```
npm run test:vitest
```
- Viewing the code coverage of a single test file:
```
npm run test:vitest:coverage /path/to/test/file
```
- Viewing the code coverage of all test files:
```
npm run test:vitest:coverage
```

#### Combined testing and coverage
- Running all tests:
```
npm run test && npm run test:vitest
```
- Viewing combined code coverage:
```
npm run test --watchAll=false --coverage && npm run test:vitest:coverage
```

#### Test Code Coverage:

1. _General Information_
- The current code coverage of the repo is: [![codecov](https://codecov.io/gh/PalisadoesFoundation/talawa-admin/branch/develop/graph/badge.svg?token=II0R0RREES)](https://codecov.io/gh/PalisadoesFoundation/talawa-admin)
- You can determine the percentage test coverage of your code by running these two commands in sequence:
```
npm install
npm run test --watchAll=false --coverage
genhtml coverage/lcov.info -o coverage
```
- The output of the `npm run test` command will give you a tablular coverage report per file
- The overall coverage rate will be visible on the penultimate line of the `genhtml` command's output.
- The `genhtml` command is part of the Linux `lcov` package. Similar packages can be found for Windows and MacOS.
- The currently acceptable coverage rate can be found in the [GitHub Pull Request file](.github/workflows/pull-requests.yml). Search for the value below the line containing `min_coverage`.
2. _Testing Individual Files_
- You can test an individual file by running this command:
```
npm run test --watchAll=false /path/to/test/file
```
- You can get the test coverage report for that file by running this command. The report will list all tests in the suite. Those tests that are not run will have zero values. You will need to look for the output line relevant to your test file.
```
npm run test --watchAll=false --coverage /path/to/test/file
```
3. _Creating your code coverage account_

- You can also see your code coverage online for your fork of the repo. This is provided by `codecov.io`

1. Go to this link: `https://app.codecov.io/gh/XXXX/YYYY` where XXXX is your GitHub account username and YYYY is the name of the repository
2. Login to `codecov.io` using your GitHub account, and add your **repo** and **branches** to the `codecov.io` dashboard.
![Debugging Test Demo](/public/images/codecov/authorise-codecov-github.jpg)
3. Remember to add the `Repository Upload Token` for your forked repo. This can be found under `Settings` of your `codecov.io` account.

4. Click on Setup Repo option
![Debugging Test Demo](</public/images/codecov/homescrenn%20(1).jpg>)
5. Use the value of this token to create a secret named CODE_COV for your forked repo.
[![Code-cov-token.jpg](/public/images/codecov/Code-cov-token.jpg)]()
[![addd-your-key.jpg](/public/images/codecov/addd-your-key.jpg)]()
6. You will see your code coverage reports with every push to your repo after following these steps
[![results.jpg](/public/images/codecov/results.jpg)]()

#### Jest Testing

- Running a single test:
```
npm run test path/to/test/file
```
- Running all tests:
```
npm run test --watchAll=false
```
- Viewing the code coverage of a single test file:
```
npm run test --watchAll=false --coverage /path/to/test/file
```
- Viewing the code coverage of all test files:
```
npm run test --watchAll=false --coverage
```
- Debug tests in browser
You can see the output of failing tests in broswer by running `jest-preview` package before running your tests

```
npm run jest-preview
npm run test --watchAll=false --coverage
```

You don't need to re-run the `npm run jest-preview` command each time, simply run the `npm run test` command if the Jest Preview server is already running in the background, it'll automatically detect any failing tests and show the preview at `http://localhost:3336` as shown in this screenshot -

![Debugging Test Demo](./public/images/jest-preview.webp)

#### Vitest Testing

- Running a single test:
```
npm run test:vitest /path/to/test/file
```
- Running all tests:
```
npm run test:vitest
```
- Viewing the code coverage of a single test file:
```
npm run test:vitest:coverage /path/to/test/file
```
- Viewing the code coverage of all test files:
```
npm run test:vitest:coverage
```

#### Combined testing and coverage

- Running all tests:
```
npm run test && npm run test:vitest
```
- Viewing combined code coverage:
```
npm run test --watchAll=false --coverage && npm run test:vitest:coverage
```

#### Test Code Coverage:

1. _General Information_
- The current code coverage of the repo is: [![codecov](https://codecov.io/gh/PalisadoesFoundation/talawa-admin/branch/develop/graph/badge.svg?token=II0R0RREES)](https://codecov.io/gh/PalisadoesFoundation/talawa-admin)
- You can determine the percentage test coverage of your code by running these two commands in sequence:
```
npm install
npm run test --watchAll=false --coverage
genhtml coverage/lcov.info -o coverage
```
- The output of the `npm run test` command will give you a tablular coverage report per file
- The overall coverage rate will be visible on the penultimate line of the `genhtml` command's output.
- The `genhtml` command is part of the Linux `lcov` package. Similar packages can be found for Windows and MacOS.
- The currently acceptable coverage rate can be found in the [GitHub Pull Request file](.github/workflows/pull-requests.yml). Search for the value below the line containing `min_coverage`.
2. _Testing Individual Files_
- You can test an individual file by running this command:
```
npm run test --watchAll=false /path/to/test/file
```
- You can get the test coverage report for that file by running this command. The report will list all tests in the suite. Those tests that are not run will have zero values. You will need to look for the output line relevant to your test file.
```
npm run test --watchAll=false --coverage /path/to/test/file
```
3. _Creating your code coverage account_

- You can also see your code coverage online for your fork of the repo. This is provided by `codecov.io`

1. Go to this link: `https://app.codecov.io/gh/XXXX/YYYY` where XXXX is your GitHub account username and YYYY is the name of the repository
2. Login to `codecov.io` using your GitHub account, and add your **repo** and **branches** to the `codecov.io` dashboard.
![Debugging Test Demo](/public/images/codecov/authorise-codecov-github.jpg)
3. Remember to add the `Repository Upload Token` for your forked repo. This can be found under `Settings` of your `codecov.io` account.

4. Click on Setup Repo option
![Debugging Test Demo](</public/images/codecov/homescrenn%20(1).jpg>)
5. Use the value of this token to create a secret named CODE_COV for your forked repo.
[![Code-cov-token.jpg](/public/images/codecov/Code-cov-token.jpg)]()
[![addd-your-key.jpg](/public/images/codecov/addd-your-key.jpg)]()
6. You will see your code coverage reports with every push to your repo after following these steps
[![results.jpg](/public/images/codecov/results.jpg)]()

1. After making changes you can add them to git locally using `git add <file_name>`(to add changes only in a particular file) or `git add .` (to add all changes).
1. After adding the changes you need to commit them using `git commit -m '<commit message>'`(look at the commit guidelines below for commit messages).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ Defined in: [src/GraphQl/Mutations/mutations.ts:496](https://github.com/Palisado

## Remarks

used `updatePluginStatus`to add or remove the current Organization the in the plugin list `uninstalledOrgs`
Used `updatePluginStatus` to add or remove the current organization in the plugin list `uninstalledOrgs`.
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ A promise that resolves to the store data in JSON format.

> **generateLinks**(`plugins`): `object`[]

Defined in: [src/components/AddOn/support/services/Plugin.helper.ts:32](https://github.com/PalisadoesFoundation/talawa-admin/blob/main/src/components/AddOn/support/services/Plugin.helper.ts#L32)
Defined in: [src/components/AddOn/support/services/Plugin.helper.ts:34](https://github.com/PalisadoesFoundation/talawa-admin/blob/main/src/components/AddOn/support/services/Plugin.helper.ts#L34)

Generates an array of links for the enabled plugins.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,6 @@ Defined in: [src/types/AddOn/interface.ts:33](https://github.com/PalisadoesFound

## Properties

### \_id

> **\_id**: `string`

Defined in: [src/types/AddOn/interface.ts:34](https://github.com/PalisadoesFoundation/talawa-admin/blob/main/src/types/AddOn/interface.ts#L34)

***

### component

> **component**: `string`
Expand All @@ -32,6 +24,14 @@ Defined in: [src/types/AddOn/interface.ts:41](https://github.com/PalisadoesFound

***

### id

> **id**: `string`

Defined in: [src/types/AddOn/interface.ts:34](https://github.com/PalisadoesFoundation/talawa-admin/blob/main/src/types/AddOn/interface.ts#L34)

***

### installed

> **installed**: `boolean`
Expand Down
2 changes: 1 addition & 1 deletion schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -1813,7 +1813,7 @@ enum PaginationDirection {
scalar PhoneNumber

type Plugin {
_id: ID!
id: ID!
pluginCreatedBy: String!
pluginDesc: String!
pluginName: String!
Expand Down
14 changes: 7 additions & 7 deletions src/GraphQl/Mutations/mutations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -477,9 +477,9 @@ export const FORGOT_PASSWORD_MUTATION = gql`
* used to toggle `installStatus` (boolean value) of a Plugin
*/
export const UPDATE_INSTALL_STATUS_PLUGIN_MUTATION = gql`
mutation ($id: ID!, $orgId: ID!) {
updatePluginStatus(id: $id, orgId: $orgId) {
_id
mutation ($pluginId: String!, $orgId: String!) {
updatePluginStatus(pluginId: $pluginId, orgId: $orgId) {
id
pluginName
pluginCreatedBy
pluginDesc
Expand All @@ -491,12 +491,12 @@ export const UPDATE_INSTALL_STATUS_PLUGIN_MUTATION = gql`
/**
* {@label UPDATE_ORG_STATUS_PLUGIN_MUTATION}
* @remarks
* used `updatePluginStatus`to add or remove the current Organization the in the plugin list `uninstalledOrgs`
* Used `updatePluginStatus` to add or remove the current organization in the plugin list `uninstalledOrgs`.
*/
export const UPDATE_ORG_STATUS_PLUGIN_MUTATION = gql`
mutation update_install_status_plugin_mutation($id: ID!, $orgId: ID!) {
updatePluginStatus(id: $id, orgId: $orgId) {
_id
mutation updateOrgStatusPluginMutation($pluginId: String!, $orgId: String!) {
updatePluginStatus(pluginId: $pluginId, orgId: $orgId) {
id
pluginName
pluginCreatedBy
pluginDesc
Expand Down
2 changes: 1 addition & 1 deletion src/GraphQl/Queries/PlugInQueries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import gql from 'graphql-tag';
export const PLUGIN_GET = gql`
query getPluginList {
getPlugins {
_id
id
pluginName
pluginCreatedBy
pluginDesc
Expand Down
2 changes: 1 addition & 1 deletion src/components/AddOn/core/AddOnEntry/AddOnEntry.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ function addOnEntry({
setButtonLoading(true);
await addOrgAsUninstalled({
variables: {
id: id.toString(),
pluginId: id.toString(),
orgId: currentOrg.toString(),
},
});
Expand Down
13 changes: 9 additions & 4 deletions src/components/AddOn/core/AddOnStore/AddOnStore.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,18 @@ function addOnStore(): JSX.Element {
* Fetches store plugins and updates the Redux store with the plugin data.
*/
const getStorePlugins = async (): Promise<void> => {
console.log('Entered in getStorePlugins');
let plugins = await new PluginHelper().fetchStore();

const installIds = (await new PluginHelper().fetchInstalled()).map(
(plugin: InterfacePluginHelper) => plugin._id,
(plugin: InterfacePluginHelper) => plugin.id,
);

plugins = plugins.map((plugin: InterfacePluginHelper) => {
plugin.installed = installIds.includes(plugin._id);
plugin.installed = installIds.includes(plugin.id);
return plugin;
});

store.dispatch({ type: 'UPDATE_STORE', payload: plugins });
};

Expand Down Expand Up @@ -86,6 +90,7 @@ function addOnStore(): JSX.Element {
plugins: InterfacePluginHelper[],
searchTerm: string,
): InterfacePluginHelper[] => {
console.log('Plugin is triggered: ', plugins);
if (!searchTerm) {
return plugins;
}
Expand Down Expand Up @@ -172,7 +177,7 @@ function addOnStore(): JSX.Element {
{filteredPlugins.map((plug, i) => (
<div className={styles.cardGridItem} key={i}>
<AddOnEntry
id={plug._id}
id={plug.id}
title={plug.pluginName}
description={plug.pluginDesc}
createdBy={plug.pluginCreatedBy}
Expand Down Expand Up @@ -210,7 +215,7 @@ function addOnStore(): JSX.Element {
return filteredPlugins.map((plug, i) => (
<div className={styles.cardGridItem} key={i}>
<AddOnEntry
id={plug._id}
id={plug.id}
title={plug.pluginName}
description={plug.pluginDesc}
createdBy={plug.pluginCreatedBy}
Expand Down
4 changes: 3 additions & 1 deletion src/components/AddOn/support/services/Plugin.helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ class PluginHelper {
* @returns A promise that resolves to the installed plugins data in JSON format.
*/
fetchInstalled = async (): Promise<any> => {
const result = await fetch(`http://localhost:3005/installed`);
const result = await fetch(
`http://localhost:${process.env.PORT}/installed`,
);
return await result.json();
};

Expand Down
Loading
Loading