From 0ca595ee37decfd22239b7c0b9ea738be3e8abbb Mon Sep 17 00:00:00 2001 From: Aaditya Agarwal Date: Fri, 20 Dec 2024 06:57:39 +0530 Subject: [PATCH 1/2] Updated setup.ts to support docker compose v2 and pass npm run typecheck (#2770) * updated setup.ts to support docker compose v2 * updated setup.ts to support docker compose v1 and v2 * removed erroneous empty gql block from unions.ts * improved error and time handling in setup.ts * fixed incorrect test * removed debug log * removed minio.deb which got committed by mistake --- setup.ts | 51 +++++++++++++++---- src/typeDefs/unions.ts | 4 +- .../resolvers/Query/getVolunteerRanks.spec.ts | 3 +- 3 files changed, 45 insertions(+), 13 deletions(-) diff --git a/setup.ts b/setup.ts index b8ad43ecc3..bad4b347bd 100644 --- a/setup.ts +++ b/setup.ts @@ -5,7 +5,7 @@ import fs from "fs"; import inquirer from "inquirer"; import path from "path"; import type { ExecException } from "child_process"; -import { exec, spawn } from "child_process"; +import { exec, spawn, execSync } from "child_process"; import { MongoClient } from "mongodb"; import { MAXIMUM_IMAGE_SIZE_LIMIT_KB } from "./src/constants"; import { @@ -466,6 +466,25 @@ export async function mongoDB(): Promise { For Docker setup */ +function getDockerComposeCommand(): { command: string; args: string[] } { + let dockerComposeCmd = "docker-compose"; // Default to v1 + let args = ["-f", "docker-compose.dev.yaml", "up", "--build", "-d"]; + + try { + // Test if 'docker compose' works (v2) + execSync("docker compose version", { stdio: "ignore" }); + dockerComposeCmd = "docker"; + args = ["compose", ...args]; // Prefix 'compose' for v2 + } catch (error) { + console.log(error); + dockerComposeCmd = + process.platform === "win32" ? "docker-compose.exe" : "docker-compose"; + } + + return { command: dockerComposeCmd, args }; +} + +const DOCKER_COMPOSE_TIMEOUT_MS = 300000; async function runDockerComposeWithLogs(): Promise { // Check if Docker daemon is running try { @@ -479,35 +498,47 @@ async function runDockerComposeWithLogs(): Promise { dockerCheck.on("close", (code) => code === 0 ? resolve(null) - : reject(new Error("Docker daemon not running")), + : reject( + new Error( + "Docker daemon not running. Please ensure Docker Desktop is running and try again.", + ), + ), ); }); } catch (error: unknown) { const errorMessage = error instanceof Error ? error.message : String(error); throw new Error( - `Docker daemon is not running. Please start Docker and try again. Details: ${errorMessage}`, + `Docker daemon check failed. Please ensure: + 1. Docker Desktop is installed and running + 2. You have necessary permissions + 3. Docker service is healthy + Details: ${errorMessage}`, ); } return new Promise((resolve, reject) => { + const { command, args } = getDockerComposeCommand(); + let isCompleted = false; + + const dockerCompose = spawn(command, args, { stdio: "inherit" }); + const timeout = setTimeout(() => { + if (isCompleted) return; dockerCompose.kill(); reject(new Error("Docker compose operation timed out after 5 minutes")); - }, 300000); - - const dockerCompose = spawn( - process.platform === "win32" ? "docker-compose.exe" : "docker-compose", - ["-f", "docker-compose.dev.yaml", "up", "--build", "-d"], - { stdio: "inherit" }, - ); + }, DOCKER_COMPOSE_TIMEOUT_MS); dockerCompose.on("error", (error) => { + if (isCompleted) return; + isCompleted = true; clearTimeout(timeout); console.error("Error running docker-compose:", error); reject(error); }); dockerCompose.on("close", (code) => { + if (isCompleted) return; + isCompleted = true; clearTimeout(timeout); if (code === 0) { console.log("Docker Compose completed successfully."); diff --git a/src/typeDefs/unions.ts b/src/typeDefs/unions.ts index d9c6501960..d19e478891 100644 --- a/src/typeDefs/unions.ts +++ b/src/typeDefs/unions.ts @@ -1,4 +1,4 @@ -import { gql } from "graphql-tag"; +// import { gql } from "graphql-tag"; // Place fields alphabetically to ensure easier lookup and navigation. -export const unions = gql``; +// export const unions = gql``; diff --git a/tests/resolvers/Query/getVolunteerRanks.spec.ts b/tests/resolvers/Query/getVolunteerRanks.spec.ts index 0f5d6973d5..67060e0bcc 100644 --- a/tests/resolvers/Query/getVolunteerRanks.spec.ts +++ b/tests/resolvers/Query/getVolunteerRanks.spec.ts @@ -76,7 +76,8 @@ describe("resolvers -> Query -> getVolunteerRanks", () => { }, {}, )) as unknown as VolunteerRank[]; - expect(volunteerRanks[0].hoursVolunteered).toEqual(2); + + expect(volunteerRanks[0].hoursVolunteered).toEqual(6); expect(volunteerRanks[0].user._id).toEqual(testUser1?._id); expect(volunteerRanks[0].rank).toEqual(1); }); From 039b0f127fb8caa46d57186ab4b3bb27fe150903 Mon Sep 17 00:00:00 2001 From: Bandhan Majumder <133476557+bandhan-majumder@users.noreply.github.com> Date: Sat, 21 Dec 2024 03:25:06 +0530 Subject: [PATCH 2/2] fix: Upgraded package typescript from 5.5.4 to 5.6.2 : fixes #2538 (#2766) * Update package.json * Update package-lock.json * Update tsconfig.json * Update createVenue.ts * Update tsconfig.json * Update tsconfig.json * Update createVenue.spec.ts * Updated format --- package-lock.json | 9 +-- package.json | 2 +- src/resolvers/Mutation/createVenue.ts | 2 +- tests/resolvers/Mutation/createVenue.spec.ts | 76 ++++++++++++++++++++ tsconfig.json | 3 +- 5 files changed, 85 insertions(+), 7 deletions(-) diff --git a/package-lock.json b/package-lock.json index 15f555b34c..86a4f38b51 100644 --- a/package-lock.json +++ b/package-lock.json @@ -113,7 +113,7 @@ "rimraf": "^6.0.1", "supertest": "^7.0.0", "tsx": "^4.19.1", - "typescript": "^5.5.4", + "typescript": "^5.6.2", "vitest": "^2.1.3" } }, @@ -18737,9 +18737,10 @@ } }, "node_modules/typescript": { - "version": "5.5.4", - "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.5.4.tgz", - "integrity": "sha512-Mtq29sKDAEYP7aljRgtPOpTvOfbwRWlS6dPRzwjdE+C0R4brX/GUyhHSecbHMFLNBLcJIPt9nl9yG5TZ1weH+Q==", + "version": "5.6.3", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.6.3.tgz", + "integrity": "sha512-hjcS1mhfuyi4WW8IWtjP7brDrG2cuDZukyrYrSauoXGNgx0S7zceP07adYkJycEr56BOUTNPzbInooiN3fn1qw==", + "license": "Apache-2.0", "bin": { "tsc": "bin/tsc", "tsserver": "bin/tsserver" diff --git a/package.json b/package.json index a2f250820a..754a0e5aff 100644 --- a/package.json +++ b/package.json @@ -151,7 +151,7 @@ "rimraf": "^6.0.1", "supertest": "^7.0.0", "tsx": "^4.19.1", - "typescript": "^5.5.4", + "typescript": "^5.6.2", "vitest": "^2.1.3" }, "overrides": { diff --git a/src/resolvers/Mutation/createVenue.ts b/src/resolvers/Mutation/createVenue.ts index f1f7398fdf..65d6491237 100644 --- a/src/resolvers/Mutation/createVenue.ts +++ b/src/resolvers/Mutation/createVenue.ts @@ -111,7 +111,7 @@ export const createVenue: MutationResolvers["createVenue"] = async ( } // Check if the venue name provided is an empty string. - if (!args.data?.name ?? "") { + if (!(args.data?.name ?? "")) { throw new errors.InputValidationError( requestContext.translate(VENUE_NAME_MISSING_ERROR.MESSAGE), VENUE_NAME_MISSING_ERROR.CODE, diff --git a/tests/resolvers/Mutation/createVenue.spec.ts b/tests/resolvers/Mutation/createVenue.spec.ts index 1bdb943849..4d48976880 100644 --- a/tests/resolvers/Mutation/createVenue.spec.ts +++ b/tests/resolvers/Mutation/createVenue.spec.ts @@ -186,6 +186,82 @@ describe("resolvers -> Mutation -> createVenue", () => { } }); + it(`throws InputValidationError if the venue name is undefined`, async () => { + try { + await Organization.findByIdAndUpdate( + { + _id: testOrganization?._id, + }, + { + $push: { + admins: [testUser?.id], + }, + }, + ); + + const args: MutationCreateVenueArgs = { + data: { + capacity: 10, + name: undefined as unknown as string, + organizationId: testOrganization?.id, + }, + }; + + const context = { + userId: testUser?.id, + }; + + const { createVenue } = await import( + "../../../src/resolvers/Mutation/createVenue" + ); + await createVenue?.({}, args, context); + } catch (error: unknown) { + if (error instanceof InputValidationError) { + expect(error.message).toEqual(VENUE_NAME_MISSING_ERROR.MESSAGE); + } else { + fail(`Expected InputValidationError, but got ${error}`); + } + } + }); + + it(`throws InputValidationError if the venue name is null`, async () => { + try { + await Organization.findByIdAndUpdate( + { + _id: testOrganization?._id, + }, + { + $push: { + admins: [testUser?.id], + }, + }, + ); + + const args: MutationCreateVenueArgs = { + data: { + capacity: 10, + name: null as unknown as string, + organizationId: testOrganization?.id, + }, + }; + + const context = { + userId: testUser?.id, + }; + + const { createVenue } = await import( + "../../../src/resolvers/Mutation/createVenue" + ); + await createVenue?.({}, args, context); + } catch (error: unknown) { + if (error instanceof InputValidationError) { + expect(error.message).toEqual(VENUE_NAME_MISSING_ERROR.MESSAGE); + } else { + fail(`Expected InputValidationError, but got ${error}`); + } + } + }); + it(`throws ConflictError if a venue with same place already exists in the organization`, async () => { try { const args: MutationCreateVenueArgs = { diff --git a/tsconfig.json b/tsconfig.json index ea514189e2..4406567923 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -6,6 +6,7 @@ "forceConsistentCasingInFileNames": true /* Ensure that casing is correct in imports. */, "strict": true /* Enable all strict type-checking options. */, "skipLibCheck": true /* Skip type checking all .d.ts files. */, - "resolveJsonModule": true /* Allow to import JSON files */ + "resolveJsonModule": true /* Allow to import JSON files */, + "noUncheckedSideEffectImports": true /* Checks if module's path exists. */ } }