Skip to content

Commit 8fb5aa8

Browse files
'Merge branch 'ActionItemCategory' of https://github.com/NishantSinghhhhh/talawa-api into ActionItemCategory
2 parents 9f8d528 + 42610e6 commit 8fb5aa8

File tree

5 files changed

+195
-21
lines changed

5 files changed

+195
-21
lines changed

.github/workflows/pull-request.yml

+53
Original file line numberDiff line numberDiff line change
@@ -348,3 +348,56 @@ jobs:
348348
echo "- Contributor may be merging into an incorrect branch."
349349
echo "- Source branch may be incorrect please use develop as source branch."
350350
exit 1
351+
352+
Check-App-Startup:
353+
name: Check App Startup and Health
354+
runs-on: ubuntu-latest
355+
needs: [Run-Tests]
356+
steps:
357+
- name: Checkout repository
358+
uses: actions/[email protected]
359+
- name: Install Devcontainer CLI
360+
run: npm install -g @devcontainers/cli
361+
- name: Copy devcontainer environment file
362+
run: cp envFiles/.env.devcontainer .env
363+
- name: Bring up devcontainer
364+
run: devcontainer up --workspace-folder .
365+
- name: Wait for Devcontainer to be ready
366+
run: |
367+
echo "Waiting for devcontainer services to be ready..."
368+
sleep 10
369+
- name: Verify Running Containers
370+
run: docker ps
371+
- name: Install dependencies inside the container
372+
run: docker exec talawa-api-1 /bin/bash -c 'pnpm install'
373+
- name: Start server and monitor logs
374+
run: |
375+
docker exec talawa-api-1 /bin/bash -c 'pnpm run start_development_server' &
376+
sleep 10
377+
- name: Wait for GraphQL endpoint to become available
378+
if: always()
379+
run: |
380+
echo "Waiting for the GraphQL endpoint to become available..."
381+
for i in {1..60}; do
382+
# Check if container exists first
383+
if ! docker ps | grep -q talawa-api-1; then
384+
echo "Container talawa-api-1 not found. Waiting..."
385+
sleep 2
386+
continue
387+
fi
388+
docker exec talawa-api-1 which curl >/dev/null 2>&1 || {
389+
docker exec talawa-api-1 apt-get update && docker exec talawa-api-1 apt-get install -y curl
390+
}
391+
RESPONSE=$(docker exec talawa-api-1 curl -s -X POST http://127.0.0.1:4000/graphql -H "Content-Type: application/json" -d '{"query":"{__typename}"}' 2>/dev/null || echo "Connection failed")
392+
if echo "$RESPONSE" | grep -q '__typename'; then
393+
echo "GraphQL endpoint is available!"
394+
exit 0
395+
fi
396+
echo "GraphQL endpoint not ready. Retrying in 2 seconds..."
397+
sleep 2
398+
done
399+
echo "GraphQL endpoint did not become available within the expected time."
400+
exit 1
401+
- name: Cleanup - Free ports by stopping containers
402+
if: always()
403+
run: docker compose down

package.json

-2
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@
3232
"minio": "^8.0.4",
3333
"postgres": "^3.4.5",
3434
"ulidx": "^2.4.1",
35-
"uuid": "^11.1.0",
3635
"uuidv7": "^1.0.2",
3736
"zod": "^3.24.2"
3837
},
@@ -43,7 +42,6 @@
4342
"@swc/cli": "0.6.0",
4443
"@swc/core": "^1.11.5",
4544
"@types/node": "^22.13.17",
46-
"@types/uuid": "^10.0.0",
4745
"@vitest/coverage-v8": "^3.1.1",
4846
"drizzle-kit": "^0.30.6",
4947
"drizzle-seed": "^0.3.1",

pnpm-lock.yaml

-17
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

scripts/dbManagement/helpers.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import {
1414
envConfigSchema,
1515
envSchemaAjv,
1616
} from "src/envConfigSchema";
17-
import { v4 as uuidv4 } from "uuid";
17+
import { uuidv7 } from "uuidv7";
1818

1919
const envConfig = envSchema<EnvConfig>({
2020
ajv: envSchemaAjv,
@@ -593,7 +593,7 @@ export async function insertCollections(
593593
updaterId: string;
594594
}) => ({
595595
...action_item,
596-
id: action_item.id.length === 36 ? action_item.id : uuidv4(),
596+
id: action_item.id.length === 36 ? action_item.id : uuidv7(),
597597
assignedAt: parseDate(action_item.assignedAt),
598598
completionAt: parseDate(action_item.completionAt),
599599
createdAt: parseDate(action_item.createdAt),

test/scripts/dbManagement/helpers.test.ts

+140
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import fs from "node:fs/promises";
22
import readline from "node:readline";
33
import * as schema from "src/drizzle/schema";
44
import type { TestEnvConfig } from "test/envConfigSchema";
5+
import { uuidv7 } from "uuidv7";
56
import { beforeAll, expect, suite, test, vi } from "vitest";
67

78
let testEnvConfig: TestEnvConfig;
@@ -72,6 +73,32 @@ suite.concurrent("parseDate", () => {
7273
});
7374
});
7475

76+
suite.concurrent("action item ID generation", () => {
77+
test.concurrent(
78+
"should generate new uuidv7 when ID is not 36 characters",
79+
async () => {
80+
const actionItem = {
81+
id: "short-id",
82+
assignedAt: "2024-03-14",
83+
completionAt: "2024-03-15",
84+
createdAt: "2024-03-13",
85+
updaterId: "user-123",
86+
};
87+
88+
const result = {
89+
...actionItem,
90+
id: actionItem.id.length === 36 ? actionItem.id : uuidv7(),
91+
assignedAt: helpers.parseDate(actionItem.assignedAt),
92+
completionAt: helpers.parseDate(actionItem.completionAt),
93+
createdAt: helpers.parseDate(actionItem.createdAt),
94+
};
95+
96+
expect(result.id).not.toBe("short-id");
97+
expect(result.id.length).toBe(36);
98+
},
99+
);
100+
});
101+
75102
suite.concurrent("askUserToContinue", () => {
76103
test.concurrent("should resolve to true when user inputs 'y'", async () => {
77104
const fakeInterface = {
@@ -256,6 +283,119 @@ suite.concurrent("insertCollections", () => {
256283
).rejects.toThrow(/Error adding data to tables:/);
257284
},
258285
);
286+
287+
test.concurrent(
288+
"should generate new uuidv7 for action items with short IDs",
289+
async () => {
290+
const userId = uuidv7();
291+
await helpers.checkAndInsertData(
292+
schema.usersTable,
293+
[
294+
{
295+
id: userId,
296+
emailAddress: "[email protected]",
297+
name: "Test User",
298+
passwordHash: "hashed_password_123",
299+
isEmailAddressVerified: true,
300+
role: "regular",
301+
createdAt: new Date(),
302+
updatedAt: new Date(),
303+
},
304+
],
305+
schema.usersTable.id,
306+
1000,
307+
);
308+
309+
const organizationId = "123e4567-e89b-12d3-a456-426614174000";
310+
await helpers.checkAndInsertData(
311+
schema.organizationsTable,
312+
[
313+
{
314+
id: organizationId,
315+
name: "Test Organizations",
316+
description: "Test organization description",
317+
createdAt: new Date(),
318+
updatedAt: new Date(),
319+
creatorId: userId,
320+
updaterId: userId,
321+
isUserRegistrationRequired: false,
322+
},
323+
],
324+
schema.organizationsTable.id,
325+
1000,
326+
);
327+
328+
const categoryId = "123e4567-e89b-12d3-a456-426614174001";
329+
await helpers.checkAndInsertData(
330+
schema.actionCategoriesTable,
331+
[
332+
{
333+
id: categoryId,
334+
name: "Test Category",
335+
description: "Test category description",
336+
createdAt: new Date(),
337+
updatedAt: new Date(),
338+
creatorId: userId,
339+
updaterId: userId,
340+
organizationId: organizationId,
341+
isDisabled: false,
342+
},
343+
],
344+
schema.actionCategoriesTable.id,
345+
1000,
346+
);
347+
const mockActionItem = {
348+
id: "short-id",
349+
assignedAt: "2024-03-14",
350+
completionAt: "2024-03-15",
351+
createdAt: "2024-03-13",
352+
updatedAt: "2024-03-13",
353+
preCompletionNotes: "Test notes",
354+
postCompletionNotes: "",
355+
organizationId: organizationId,
356+
categoryId: categoryId,
357+
eventId: null,
358+
assigneeId: userId,
359+
creatorId: userId,
360+
updaterId: userId,
361+
isCompleted: false,
362+
};
363+
364+
let capturedData: (typeof schema.actionsTable.$inferInsert)[] = [];
365+
const checkAndInsertDataSpy = vi
366+
.spyOn(helpers, "checkAndInsertData")
367+
.mockImplementation((table, data) => {
368+
capturedData = data as (typeof schema.actionsTable.$inferInsert)[];
369+
return Promise.resolve(true);
370+
});
371+
372+
const actionItemWithUuid = {
373+
...mockActionItem,
374+
id: uuidv7(),
375+
assignedAt: helpers.parseDate(mockActionItem.assignedAt),
376+
completionAt: helpers.parseDate(mockActionItem.completionAt),
377+
createdAt: helpers.parseDate(mockActionItem.createdAt),
378+
updatedAt: helpers.parseDate(mockActionItem.updatedAt),
379+
};
380+
381+
await helpers.checkAndInsertData(
382+
schema.actionsTable,
383+
[actionItemWithUuid],
384+
schema.actionsTable.id,
385+
1000,
386+
);
387+
388+
expect(capturedData.length).toBeGreaterThan(0);
389+
const firstItem = capturedData[0];
390+
if (!firstItem || !firstItem.id) {
391+
throw new Error("Expected action item with ID");
392+
}
393+
expect(firstItem.id).not.toBe("short-id");
394+
expect(firstItem.id.length).toBe(36);
395+
396+
checkAndInsertDataSpy.mockRestore();
397+
},
398+
);
259399
});
260400

261401
suite.concurrent("checkDataSize integration test", () => {

0 commit comments

Comments
 (0)