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

Merge from develop-postgres prior to code freeze #3234

Merged
merged 2 commits into from
Jan 10, 2025
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 0 additions & 2 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
#!/usr/bin/env sh
. "$(dirname -- "$0")/_/husky.sh"

Check warning on line 1 in .husky/pre-commit

View workflow job for this annotation

GitHub Actions / Performs linting, formatting, type-checking, checking for different source and target branch

File ignored by default.
npm run format:fix
# npm run lint:fix
npm run lint-staged
Expand Down
4 changes: 2 additions & 2 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@ export default {
],
coverageThreshold: {
global: {
lines: 20,
statements: 20,
lines: 1,
statements: 1,
},
},
testPathIgnorePatterns: [
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@
"format:check": "prettier --check \"**/*.{ts,tsx,json,scss,css}\"",
"check-tsdoc": "node .github/workflows/check-tsdoc.js",
"typecheck": "tsc --project tsconfig.json --noEmit",
"prepare": "husky install",
"prepare": "husky",
"jest-preview": "jest-preview",
"update:toc": "node scripts/githooks/update-toc.js",
"lint-staged": "lint-staged --concurrent false",
Expand Down
1 change: 1 addition & 0 deletions public/locales/en/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -1262,6 +1262,7 @@
"endOfResults": "endOfResults"
},
"userChat": {
"title": "Chats",
"add": "Add",
"chat": "Chat",
"search": "Search",
Expand Down
1 change: 1 addition & 0 deletions public/locales/fr/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -1262,6 +1262,7 @@
"endOfResults": "Fin des résultats"
},
"userChat": {
"title": "Discussions",
"add": "Ajouter",
"chat": "Chat",
"contacts": "Contacts",
Expand Down
1 change: 1 addition & 0 deletions public/locales/hi/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -1262,6 +1262,7 @@
"endOfResults": "परिणाम समाप्त"
},
"userChat": {
"title": "चैट्स",
"add": "जोड़ें",
"chat": "बात करना",
"contacts": "संपर्क",
Expand Down
1 change: 1 addition & 0 deletions public/locales/sp/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -1265,6 +1265,7 @@
"createAdvertisement": "Crear publicidad"
},
"userChat": {
"title": "Chats",
"add": "Agregar",
"chat": "Charlar",
"search": "Buscar",
Expand Down
1 change: 1 addition & 0 deletions public/locales/zh/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -1262,6 +1262,7 @@
"endOfResults": "结果结束"
},
"userChat": {
"title": "聊天",
"add": "添加",
"chat": "聊天",
"contacts": "联系方式",
Expand Down
203 changes: 53 additions & 150 deletions setup.ts
Original file line number Diff line number Diff line change
@@ -1,165 +1,48 @@
import dotenv from 'dotenv';
import fs from 'fs';
import inquirer from 'inquirer';
import { checkConnection } from './src/setup/checkConnection/checkConnection';
import { askForTalawaApiUrl } from './src/setup/askForTalawaApiUrl/askForTalawaApiUrl';
import { checkEnvFile } from './src/setup/checkEnvFile/checkEnvFile';
import { validateRecaptcha } from './src/setup/validateRecaptcha/validateRecaptcha';
import { askForCustomPort } from './src/setup/askForCustomPort/askForCustomPort';

export async function main(): Promise<void> {
console.log('Welcome to the Talawa Admin setup! 🚀');

if (!fs.existsSync('.env')) {
fs.openSync('.env', 'w');
const config = dotenv.parse(fs.readFileSync('.env.example'));
for (const key in config) {
fs.appendFileSync('.env', `${key}=${config[key]}\n`);
}
} else {
checkEnvFile();
}

let shouldSetCustomPort: boolean;

if (process.env.PORT) {
console.log(
`\nCustom port for development server already exists with the value:\n${process.env.PORT}`,
);
shouldSetCustomPort = true;
} else {
const { shouldSetCustomPortResponse } = await inquirer.prompt({
import askAndSetDockerOption from './src/setup/askAndSetDockerOption/askAndSetDockerOption';
import updateEnvFile from './src/setup/updateEnvFile/updateEnvFile';
import askAndUpdatePort from './src/setup/askAndUpdatePort/askAndUpdatePort';
import { askAndUpdateTalawaApiUrl } from './src/setup/askForDocker/askForDocker';

// Ask and set up reCAPTCHA
const askAndSetRecaptcha = async (): Promise<void> => {
try {
const { shouldUseRecaptcha } = await inquirer.prompt({

Check warning on line 14 in setup.ts

View check run for this annotation

Codecov / codecov/patch

setup.ts#L12-L14

Added lines #L12 - L14 were not covered by tests
type: 'confirm',
name: 'shouldSetCustomPortResponse',
message: 'Would you like to set up a custom port?',
name: 'shouldUseRecaptcha',
message: 'Would you like to set up reCAPTCHA?',
default: true,
});
shouldSetCustomPort = shouldSetCustomPortResponse;
}

if (shouldSetCustomPort) {
const customPort = await askForCustomPort();

const port = dotenv.parse(fs.readFileSync('.env')).PORT;

fs.readFile('.env', 'utf8', (err, data) => {
const result = data.replace(`PORT=${port}`, `PORT=${customPort}`);
fs.writeFileSync('.env', result, 'utf8');
});
}

let shouldSetTalawaApiUrl: boolean;

if (process.env.REACT_APP_TALAWA_URL) {
console.log(
`\nEndpoint for accessing talawa-api graphql service already exists with the value:\n${process.env.REACT_APP_TALAWA_URL}`,
);
shouldSetTalawaApiUrl = true;
} else {
const { shouldSetTalawaApiUrlResponse } = await inquirer.prompt({
type: 'confirm',
name: 'shouldSetTalawaApiUrlResponse',
message: 'Would you like to set up talawa-api endpoint?',
default: true,
});
shouldSetTalawaApiUrl = shouldSetTalawaApiUrlResponse;
}

if (shouldSetTalawaApiUrl) {
let isConnected = false,
endpoint = '';

while (!isConnected) {
endpoint = await askForTalawaApiUrl();
const url = new URL(endpoint);
isConnected = await checkConnection(url.origin);
}
const envPath = '.env';
const currentEnvContent = fs.readFileSync(envPath, 'utf8');
const talawaApiUrl = dotenv.parse(currentEnvContent).REACT_APP_TALAWA_URL;

const updatedEnvContent = currentEnvContent.replace(
`REACT_APP_TALAWA_URL=${talawaApiUrl}`,
`REACT_APP_TALAWA_URL=${endpoint}`,
);

fs.writeFileSync(envPath, updatedEnvContent, 'utf8');
const websocketUrl = endpoint.replace(/^http(s)?:\/\//, 'ws$1://');
const currentWebSocketUrl =
dotenv.parse(updatedEnvContent).REACT_APP_BACKEND_WEBSOCKET_URL;

const finalEnvContent = updatedEnvContent.replace(
`REACT_APP_BACKEND_WEBSOCKET_URL=${currentWebSocketUrl}`,
`REACT_APP_BACKEND_WEBSOCKET_URL=${websocketUrl}`,
);

fs.writeFileSync(envPath, finalEnvContent, 'utf8');
}

const { shouldUseRecaptcha } = await inquirer.prompt({
type: 'confirm',
name: 'shouldUseRecaptcha',
message: 'Would you like to set up ReCAPTCHA?',
default: true,
});

if (shouldUseRecaptcha) {
const useRecaptcha = dotenv.parse(
fs.readFileSync('.env'),
).REACT_APP_USE_RECAPTCHA;

fs.readFile('.env', 'utf8', (err, data) => {
const result = data.replace(
`REACT_APP_USE_RECAPTCHA=${useRecaptcha}`,
`REACT_APP_USE_RECAPTCHA=yes`,
);
fs.writeFileSync('.env', result, 'utf8');
});
let shouldSetRecaptchaSiteKey: boolean;
if (process.env.REACT_APP_RECAPTCHA_SITE_KEY) {
console.log(
`\nreCAPTCHA site key already exists with the value ${process.env.REACT_APP_RECAPTCHA_SITE_KEY}`,
);
shouldSetRecaptchaSiteKey = true;
} else {
const { shouldSetRecaptchaSiteKeyResponse } = await inquirer.prompt({
type: 'confirm',
name: 'shouldSetRecaptchaSiteKeyResponse',
message: 'Would you like to set up a reCAPTCHA site key?',
default: true,
});
shouldSetRecaptchaSiteKey = shouldSetRecaptchaSiteKeyResponse;
}

if (shouldSetRecaptchaSiteKey) {
if (shouldUseRecaptcha) {
const { recaptchaSiteKeyInput } = await inquirer.prompt([
{
type: 'input',
name: 'recaptchaSiteKeyInput',
message: 'Enter your reCAPTCHA site key:',
validate: async (input: string): Promise<boolean | string> => {
if (validateRecaptcha(input)) {
return true;
}
return 'Invalid reCAPTCHA site key. Please try again.';
validate: (input: string): boolean | string => {
return (

Check warning on line 28 in setup.ts

View check run for this annotation

Codecov / codecov/patch

setup.ts#L28

Added line #L28 was not covered by tests
validateRecaptcha(input) ||
'Invalid reCAPTCHA site key. Please try again.'
);
},
},
]);

const recaptchaSiteKey = dotenv.parse(
fs.readFileSync('.env'),
).REACT_APP_RECAPTCHA_SITE_KEY;

fs.readFile('.env', 'utf8', (err, data) => {
const result = data.replace(
`REACT_APP_RECAPTCHA_SITE_KEY=${recaptchaSiteKey}`,
`REACT_APP_RECAPTCHA_SITE_KEY=${recaptchaSiteKeyInput}`,
);
fs.writeFileSync('.env', result, 'utf8');
});
updateEnvFile('REACT_APP_RECAPTCHA_SITE_KEY', recaptchaSiteKeyInput);

Check warning on line 36 in setup.ts

View check run for this annotation

Codecov / codecov/patch

setup.ts#L36

Added line #L36 was not covered by tests
}
} catch (error) {
console.error('Error setting up reCAPTCHA:', error);
throw new Error(`Failed to set up reCAPTCHA: ${(error as Error).message}`);

Check warning on line 40 in setup.ts

View check run for this annotation

Codecov / codecov/patch

setup.ts#L39-L40

Added lines #L39 - L40 were not covered by tests
}
};

// Ask and set up logging errors in the console
const askAndSetLogErrors = async (): Promise<void> => {

Check warning on line 45 in setup.ts

View check run for this annotation

Codecov / codecov/patch

setup.ts#L45

Added line #L45 was not covered by tests
const { shouldLogErrors } = await inquirer.prompt({
type: 'confirm',
name: 'shouldLogErrors',
Expand All @@ -169,17 +52,37 @@
});

if (shouldLogErrors) {
const logErrors = dotenv.parse(fs.readFileSync('.env')).ALLOW_LOGS;

fs.readFile('.env', 'utf8', (err, data) => {
const result = data.replace(`ALLOW_LOGS=${logErrors}`, 'ALLOW_LOGS=YES');
fs.writeFileSync('.env', result, 'utf8');
});
updateEnvFile('ALLOW_LOGS', 'YES');

Check warning on line 55 in setup.ts

View check run for this annotation

Codecov / codecov/patch

setup.ts#L55

Added line #L55 was not covered by tests
}
};

console.log(
'\nCongratulations! Talawa Admin has been successfully setup! 🥂🎉',
);
// Main function to run the setup process
export async function main(): Promise<void> {
try {
console.log('Welcome to the Talawa Admin setup! 🚀');

Check warning on line 62 in setup.ts

View check run for this annotation

Codecov / codecov/patch

setup.ts#L61-L62

Added lines #L61 - L62 were not covered by tests

checkEnvFile();
await askAndSetDockerOption();
const envConfig = dotenv.parse(fs.readFileSync('.env', 'utf8'));
const useDocker = envConfig.USE_DOCKER === 'YES';

Check warning on line 67 in setup.ts

View check run for this annotation

Codecov / codecov/patch

setup.ts#L64-L67

Added lines #L64 - L67 were not covered by tests

// Only run these commands if Docker is NOT used
if (!useDocker) {
await askAndUpdatePort();
await askAndUpdateTalawaApiUrl();

Check warning on line 72 in setup.ts

View check run for this annotation

Codecov / codecov/patch

setup.ts#L71-L72

Added lines #L71 - L72 were not covered by tests
}

await askAndSetRecaptcha();
await askAndSetLogErrors();

Check warning on line 76 in setup.ts

View check run for this annotation

Codecov / codecov/patch

setup.ts#L75-L76

Added lines #L75 - L76 were not covered by tests

console.log(

Check warning on line 78 in setup.ts

View check run for this annotation

Codecov / codecov/patch

setup.ts#L78

Added line #L78 was not covered by tests
'\nCongratulations! Talawa Admin has been successfully set up! 🥂🎉',
);
} catch (error) {
console.error('\n❌ Setup failed:', error);
console.log('\nPlease try again or contact support if the issue persists.');
process.exit(1);

Check warning on line 84 in setup.ts

View check run for this annotation

Codecov / codecov/patch

setup.ts#L82-L84

Added lines #L82 - L84 were not covered by tests
}
Comment on lines +64 to +85
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Handle Missing or Corrupted .env Files Gracefully

At line 64, checkEnvFile() is called, but if the .env file is missing or corrupted, the application might crash or behave unexpectedly. Implement additional checks to handle such scenarios gracefully, informing the user and possibly regenerating a default .env file.

}

main();
21 changes: 21 additions & 0 deletions src/assets/css/app.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Empty file.
2 changes: 1 addition & 1 deletion src/components/EventCalendar/EventHeader.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ describe('EventHeader Component', () => {
fireEvent.click(getByTestId('eventType'));

await act(async () => {
fireEvent.click(getByTestId('events'));
fireEvent.click(getByTestId('Events'));
Copy link
Contributor

Choose a reason for hiding this comment

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

💡 Codebase verification

Test uses non-existent test ID

The test is trying to click an element with data-testid="Events", but this test ID doesn't exist in the component. The component only has these test IDs:

  • data-testid="searchEvent"
  • data-testid="createEventModalBtn"
🔗 Analysis chain

Verify test ID consistency with component

The test ID has been updated from 'events' to 'Events'. Please ensure this matches the test ID in the corresponding EventHeader component to prevent test failures.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for the test ID in the component file
rg -l 'data-testid=["'\'']Events["'\'']' src/components/EventCalendar/EventHeader.tsx

Length of output: 87


Script:

#!/bin/bash
# First check if the file exists
fd EventHeader.tsx src/components/EventCalendar/

# Then search for any data-testid attributes, case-insensitive
rg -i 'data-testid' src/components/EventCalendar/EventHeader.tsx

Length of output: 244

});

expect(handleChangeView).toHaveBeenCalledTimes(1);
Expand Down
Loading
Loading