-
-
Notifications
You must be signed in to change notification settings - Fork 885
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7433229
commit 064571c
Showing
1 changed file
with
57 additions
and
57 deletions.
There are no files selected for viewing
114 changes: 57 additions & 57 deletions
114
tests/resolvers/Subscription/messageSentToGroupChat.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,57 +1,57 @@ | ||
import "dotenv/config"; | ||
import { describe, it, expect, beforeAll, afterAll } from "vitest"; | ||
import { connect, disconnect } from "../../helpers/db"; | ||
import mongoose from "mongoose"; | ||
import { | ||
testGroupChatType, | ||
createTestGroupChatMessage, | ||
} from "../../helpers/groupChat"; | ||
import { filterFunction } from "../../../src/resolvers/Subscription/messageSentToGroupChat"; | ||
|
||
let MONGOOSE_INSTANCE: typeof mongoose | null; | ||
let testGroupChat: testGroupChatType; | ||
|
||
beforeAll(async () => { | ||
MONGOOSE_INSTANCE = await connect(); | ||
testGroupChat = (await createTestGroupChatMessage())[2]; | ||
}); | ||
afterAll(async () => { | ||
await disconnect(MONGOOSE_INSTANCE!); | ||
}); | ||
|
||
describe("src -> resolvers -> Subscription -> messageSentToGroupChat", () => { | ||
it("subscription filter function returns true", async () => { | ||
const { messageSentToGroupChat: messageSentToGroupChatPayload } = | ||
await import( | ||
"../../../src/resolvers/Subscription/messageSentToGroupChat" | ||
); | ||
|
||
const _args = {}; | ||
const _parent = {}; | ||
const context = { | ||
pubsub: { | ||
asyncIterator: (_action: "MESSAGE_SENT_TO_GROUP_CHAT") => { | ||
return; | ||
}, | ||
}, | ||
context: { currentUserId: testGroupChat!.users[0] }, | ||
}; | ||
const payload = { | ||
messageSentToGroupChat: { | ||
groupChatMessageBelongsTo: testGroupChat!._id, | ||
}, | ||
}; | ||
// @ts-ignore | ||
messageSentToGroupChatPayload._parent = _parent; | ||
// @ts-ignore | ||
messageSentToGroupChatPayload._args = _args; | ||
// @ts-ignore | ||
messageSentToGroupChatPayload.context = context; | ||
// @ts-ignore | ||
messageSentToGroupChatPayload.payload = payload; | ||
// @ts-ignore | ||
const x = messageSentToGroupChatPayload?.subscribe(_parent, _args, context); | ||
expect(x).not.toBe(null); | ||
expect(await filterFunction(payload, context)).toBe(true); | ||
}); | ||
}); | ||
import "dotenv/config"; | ||
import { describe, it, expect, beforeAll, afterAll } from "vitest"; | ||
import { connect, disconnect } from "../../helpers/db"; | ||
import mongoose from "mongoose"; | ||
import { | ||
testGroupChatType, | ||
createTestGroupChatMessage, | ||
} from "../../helpers/groupChat"; | ||
import { filterFunction } from "../../../src/resolvers/Subscription/messageSentToGroupChat"; | ||
|
||
let MONGOOSE_INSTANCE: typeof mongoose | null; | ||
let testGroupChat: testGroupChatType; | ||
|
||
beforeAll(async () => { | ||
MONGOOSE_INSTANCE = await connect(); | ||
testGroupChat = (await createTestGroupChatMessage())[2]; | ||
}); | ||
afterAll(async () => { | ||
await disconnect(MONGOOSE_INSTANCE!); | ||
}); | ||
|
||
describe("src -> resolvers -> Subscription -> messageSentToGroupChat", () => { | ||
it("subscription filter function returns true", async () => { | ||
const { messageSentToGroupChat: messageSentToGroupChatPayload } = | ||
await import( | ||
"../../../src/resolvers/Subscription/messageSentToGroupChat" | ||
); | ||
|
||
const _args = {}; | ||
const _parent = {}; | ||
const context = { | ||
pubsub: { | ||
asyncIterator: (_action: "MESSAGE_SENT_TO_GROUP_CHAT") => { | ||
return; | ||
}, | ||
}, | ||
context: { currentUserId: testGroupChat!.users[0] }, | ||
}; | ||
const payload = { | ||
messageSentToGroupChat: { | ||
groupChatMessageBelongsTo: testGroupChat!._id, | ||
}, | ||
}; | ||
// @ts-ignore | ||
messageSentToGroupChatPayload._parent = _parent; | ||
// @ts-ignore | ||
messageSentToGroupChatPayload._args = _args; | ||
// @ts-ignore | ||
messageSentToGroupChatPayload.context = context; | ||
// @ts-ignore | ||
messageSentToGroupChatPayload.payload = payload; | ||
// @ts-ignore | ||
const x = messageSentToGroupChatPayload?.subscribe(_parent, _args, context); | ||
expect(x).not.toBe(null); | ||
expect(await filterFunction(payload, context)).toBe(true); | ||
}); | ||
}); |