Skip to content

Commit 0a28db5

Browse files
committed
updated testing docs
1 parent cd01739 commit 0a28db5

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

docs/docs/docs/developer-resources/testing.md

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,34 +60,43 @@ The `tests/server.ts` file exports the Talawa API server instance that can be im
6060
There aren't any other strict structure requirements for the this directory.
6161

6262
# Mock GraphQL Context Factory Function
63+
6364
In Directory `test/MockContext/*`
6465

6566
## **Purpose**
67+
6668
The `createMockGraphQLContext` function provides a **fully mocked GraphQL context** for unit and integration testing of GraphQL resolvers. It ensures that resolvers can be tested **without needing a real database, MinIO storage, or authentication service** and works as centralised mocking mechanism.
6769

6870
## **Usage**
6971

7072
### **Importing the Mock Context**
73+
7174
```ts
7275
import { createMockGraphQLContext } from "test/MockContext/mockGraphQLContext";
7376
```
7477

75-
### **Creating a Mock Context**
78+
### **Creating a Mock Context**
79+
7680
#### **For an Unauthenticated User**
81+
7782
```ts
7883
const mockContext = createMockGraphQLContext(false);
7984
```
85+
8086
`mockContext.currentClient.isAuthenticated` will be `false`.
8187

8288
#### **For an Authenticated User**
89+
8390
```ts
8491
const mockContext = createMockGraphQLContext(true, "user123");
8592
```
93+
8694
`mockContext.currentClient.user.id` will be `"user123"`.
8795

8896
---
8997

9098
## **Components in Mock Context**
99+
91100
The mock context provides the following:
92101

93102
| Component | Description |
@@ -105,6 +114,7 @@ The mock context provides the following:
105114
## **How Contributors Should Use It**
106115

107116
### **Unit Testing Resolvers** (Mocks dependencies)
117+
108118
```ts
109119
test("should return user data", async () => {
110120
const mockContext = createMockGraphQLContext(true, "user123");
@@ -114,6 +124,7 @@ test("should return user data", async () => {
114124
```
115125

116126
## **Key Benefits**
127+
117128
**Isolated Testing** – No need for a real database or external services.
118129
**Scalable** – Any future changes in `GraphQLContext` can be updated in one place, ensuring a single source of truth.
119130

0 commit comments

Comments
 (0)