Skip to content

Commit

Permalink
Added tests
Browse files Browse the repository at this point in the history
  • Loading branch information
prayanshchh committed Sep 7, 2024
1 parent 3d9c4df commit e26e6a4
Show file tree
Hide file tree
Showing 8 changed files with 86 additions and 12 deletions.
2 changes: 1 addition & 1 deletion .coderabbit.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@ reviews:
- develop
- main
chat:
auto_reply: true
auto_reply: true
4 changes: 2 additions & 2 deletions INSTALLATION.md
Original file line number Diff line number Diff line change
Expand Up @@ -324,8 +324,8 @@ Follow these steps for setting up a software development environment.
```
2. Running asynchronously in a subshell. You will have to use the `docker-compose down` command below to stop it.
`bash
sudo /usr/libexec/docker/cli-plugins/docker-compose -f docker-compose.dev.yaml up --build &
`
sudo /usr/libexec/docker/cli-plugins/docker-compose -f docker-compose.dev.yaml up --build &
`
This command starts the development environment, where you can make changes to the code, and the server will automatically restart.

2. Accessing the Development Application: Open your web browser and navigate to:
Expand Down
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,11 @@ Core features include:

1. You can install the software for this repository using the steps in our [INSTALLATION.md](INSTALLATION.md) file.
1. Do you want to contribute to our code base? Look at our [CONTRIBUTING.md](CONTRIBUTING.md) file to get started. There you'll also find links to:
1. Our code of conduct documentation in the [CODE_OF_CONDUCT.md](CODE_OF_CONDUCT.md) file.
1. How we handle the processing of new and existing issues in our [ISSUE_GUIDELINES.md](ISSUE_GUIDELINES.md) file.
1. The methodologies we use to manage our pull requests in our [PR_GUIDELINES.md](PR_GUIDELINES.md) file.
1. Our code of conduct documentation in the [CODE_OF_CONDUCT.md](CODE_OF_CONDUCT.md) file.
1. How we handle the processing of new and existing issues in our [ISSUE_GUIDELINES.md](ISSUE_GUIDELINES.md) file.
1. The methodologies we use to manage our pull requests in our [PR_GUIDELINES.md](PR_GUIDELINES.md) file.
1. The `talawa` documentation can be found at our [docs.talawa.io](https://docs.talawa.io) site.
1. It is automatically generated from the markdown files stored in our [Talawa-Docs GitHub repository](https://github.com/PalisadoesFoundation/talawa-docs). This makes it easy for you to update our documenation.
1. It is automatically generated from the markdown files stored in our [Talawa-Docs GitHub repository](https://github.com/PalisadoesFoundation/talawa-docs). This makes it easy for you to update our documenation.

## Videos

Expand Down
2 changes: 1 addition & 1 deletion docker-compose.prod.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version: '3.8'
version: "3.8"

services:
mongodb:
Expand Down
1 change: 0 additions & 1 deletion scripts/cloud-api-demo/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -237,4 +237,3 @@ echo "0 * * * * talawa-api python3 reset_database.py --mongo-container develop-m
### 8.3 Logging for cron jobs

This will set up logging for the cron jobs and manage log rotation using logrotate.

2 changes: 1 addition & 1 deletion tests/helpers/userAndOrg.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export const createTestUser = async (): Promise<TestUserType> => {
password: `pass${nanoid().toLowerCase()}`,
firstName: `firstName${nanoid().toLowerCase()}`,
lastName: `lastName${nanoid().toLowerCase()}`,
image: null,
image: "exampleimageurl.com",
});
const testUserAppProfile = await AppUserProfile.create({
userId: testUser._id,
Expand Down
75 changes: 75 additions & 0 deletions tests/resolvers/Post/likedBy.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
import "dotenv/config";
import { connect, disconnect } from "../../helpers/db";
import type mongoose from "mongoose";
import { beforeAll, afterAll, describe, it, expect } from "vitest";
import type { TestPostType } from "../../helpers/posts";
import { createTestPost } from "../../helpers/posts";
import type { TestOrganizationType, TestUserType } from "../../helpers/userAndOrg";
import type { InterfacePost} from "../../../src/models";
import { Organization, Post } from "../../../src/models";
import { posts as postResolver } from "../../../src/resolvers/Organization/posts";

let testPost: TestPostType;
let testUser: TestUserType;
let testOrganization: TestOrganizationType;
let MONGOOSE_INSTANCE: typeof mongoose;

beforeAll(async () => {
MONGOOSE_INSTANCE = await connect();
[testUser, testOrganization, testPost] = await createTestPost();
await Post.updateOne(
{
_id: testPost?._id,
},
{
$push: {
likedBy: testUser?._id,
},
$inc: {
likeCount: 1,
commentCount: 1,
},
},
);
});

afterAll(async () => {
await disconnect(MONGOOSE_INSTANCE);
});

describe("resolvers -> organization -> posts", () => {
it(`returns the post object for parent post`, async () => {
const parent = await Organization.findById(testOrganization?._id).lean();

if (!parent) {
throw new Error("Parent organization not found.");
}

const postPayload = (await postResolver?.(parent, { first: 1 }, {})) as {
edges: { node: InterfacePost }[];
totalCount: number;
};

expect(postPayload).toBeDefined();
if (!postPayload) {
throw new Error("postPayload is null or undefined");
}
expect(postPayload.edges).toBeDefined();
expect(Array.isArray(postPayload.edges)).toBe(true);

const posts = await Post.find({
organization: testOrganization?._id,
}).lean();

console.log("postPayloadedge:", postPayload.edges[0].node.likedBy[0]);
console.log("posts:", posts[0].likedBy[0]);

expect(postPayload.edges.length).toEqual(posts.length);
expect(postPayload.totalCount).toEqual(posts.length);
const returnedPost = postPayload.edges[0].node;
expect(returnedPost._id).toEqual(testPost?._id.toString());
expect(returnedPost.likedBy).toHaveLength(1);
expect(returnedPost.likedBy[0]._id).toEqual(testUser?._id);
expect(returnedPost.likedBy[0].image).not.toBeNull();
});
});
4 changes: 2 additions & 2 deletions vite.config.mts
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,9 @@ export default defineConfig({
testTimeout: 30000,

// Use a thread pool for parallel execution to improve performance
pool: 'threads',
pool: "threads",

// Disable file-level parallelism to process files sequentially
fileParallelism: false,
},
});
});

0 comments on commit e26e6a4

Please sign in to comment.