-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #119 from lyve-app/test/integration-tests
Test/integration tests
- Loading branch information
Showing
9 changed files
with
283 additions
and
13 deletions.
There are no files selected for viewing
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
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 |
---|---|---|
|
@@ -56,6 +56,8 @@ cache/ | |
.env | ||
.docker/ | ||
.apps/api/prisma/migrations/ | ||
coverage | ||
|
||
|
||
yarn.lock | ||
migrations |
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
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 |
---|---|---|
@@ -0,0 +1,81 @@ | ||
import { NextFunction, Request, Response } from "express"; | ||
import httpStatus from "http-status"; | ||
import isAuth from "../../../src/middleware/isAuth"; // Replace with the path to your isAuth middleware | ||
|
||
const jwt = | ||
"eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJqZXN0IiwiaWF0IjoxNzE4ODE5MDcyLCJleHAiOjMzMzA3MjYzODcyLCJhdWQiOiJ3d3cubHl2ZS50diIsInN1YiI6IjEifQ.XiyNTx_hTMHXcXQwKmdsjvTCGcH6PJ9F02e0XrRYgCg"; | ||
describe("isAuth Middleware", () => { | ||
it("should pass authentication and call next() with user data", () => { | ||
// Mock request object | ||
const mockReq = { | ||
headers: { | ||
authorization: "Bearer " + jwt // Replace with a valid JWT token | ||
} | ||
} as Request; | ||
|
||
// Mock response object | ||
const mockRes = { | ||
status: jest.fn().mockReturnThis(), | ||
json: jest.fn() | ||
} as unknown as Response; | ||
|
||
// Mock next function | ||
const mockNext: NextFunction = jest.fn(); | ||
|
||
// Call isAuth middleware | ||
isAuth(mockReq, mockRes, mockNext); | ||
|
||
// Assertions | ||
expect(mockNext).toHaveBeenCalled(); | ||
expect(mockReq).toHaveProperty("user"); | ||
expect(mockReq.user).toBeDefined(); | ||
}); | ||
|
||
it("should handle missing authorization header", () => { | ||
// Mock request object with missing authorization header | ||
const mockReq = { | ||
headers: {} | ||
} as Request; | ||
|
||
// Mock response object | ||
const mockRes = { | ||
status: jest.fn().mockReturnThis(), | ||
json: jest.fn() | ||
} as unknown as Response; | ||
|
||
// Mock next function | ||
const mockNext: NextFunction = jest.fn(); | ||
|
||
// Call isAuth middleware | ||
isAuth(mockReq, mockRes, mockNext); | ||
|
||
// Assertions | ||
expect(mockRes.status).toHaveBeenCalledWith(httpStatus.FORBIDDEN); | ||
expect(mockRes.json).toHaveBeenCalled(); | ||
}); | ||
|
||
it("should handle invalid token", () => { | ||
// Mock request object with invalid token | ||
const mockReq = { | ||
headers: { | ||
authorization: "Bearer invalid_token" // Replace with an invalid JWT token | ||
} | ||
} as Request; | ||
|
||
// Mock response object | ||
const mockRes = { | ||
status: jest.fn().mockReturnThis(), | ||
json: jest.fn() | ||
} as unknown as Response; | ||
|
||
// Mock next function | ||
const mockNext: NextFunction = jest.fn(); | ||
|
||
// Call isAuth middleware | ||
isAuth(mockReq, mockRes, mockNext); | ||
|
||
// Assertions | ||
expect(mockRes.status).toHaveBeenCalledWith(httpStatus.FORBIDDEN); | ||
expect(mockRes.json).toHaveBeenCalled(); | ||
}); | ||
}); |
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
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 |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import { createErrorObject } from "../../../src/utils/createErrorObject"; // Adjust the path accordingly | ||
|
||
describe("createErrorObject", () => { | ||
it("should create an error object for known status code 200", () => { | ||
const result = createErrorObject(200); | ||
expect(result).toEqual([ | ||
{ | ||
name: "OK", | ||
code: 200, | ||
msg: "" | ||
} | ||
]); | ||
}); | ||
|
||
it("should create an error object for known status code 404", () => { | ||
const result = createErrorObject(404); | ||
expect(result).toEqual([ | ||
{ | ||
name: "Not Found", | ||
code: 404, | ||
msg: "" | ||
} | ||
]); | ||
}); | ||
|
||
it("should create an error object for unknown status code 999", () => { | ||
const result = createErrorObject(999); | ||
expect(result).toEqual([ | ||
{ | ||
name: "Unknown Error", | ||
code: 999, | ||
msg: "" | ||
} | ||
]); | ||
}); | ||
|
||
it("should create an error object for known status code 200 with custom message", () => { | ||
const customMsg = "Everything is good"; | ||
const result = createErrorObject(200, customMsg); | ||
expect(result).toEqual([ | ||
{ | ||
name: "OK", | ||
code: 200, | ||
msg: customMsg | ||
} | ||
]); | ||
}); | ||
|
||
it("should create an error object for unknown status code 999 with custom message", () => { | ||
const customMsg = "Something went wrong"; | ||
const result = createErrorObject(999, customMsg); | ||
expect(result).toEqual([ | ||
{ | ||
name: "Unknown Error", | ||
code: 999, | ||
msg: customMsg | ||
} | ||
]); | ||
}); | ||
}); |
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 |
---|---|---|
@@ -0,0 +1,46 @@ | ||
/* eslint-disable quotes */ | ||
import { getDayOfWeek } from "../../../src/utils/getDayOfWeek"; | ||
|
||
describe("getDayOfWeek", () => { | ||
it('should return "Wednesday" for date 2024-06-19', () => { | ||
const date = new Date("2024-06-19"); | ||
const result = getDayOfWeek(date); | ||
expect(result).toBe("Wednesday"); | ||
}); | ||
|
||
it('should return "Thursday" for date 2024-06-20', () => { | ||
const date = new Date("2024-06-20"); | ||
const result = getDayOfWeek(date); | ||
expect(result).toBe("Thursday"); | ||
}); | ||
|
||
it('should return "Friday" for date 2024-06-21', () => { | ||
const date = new Date("2024-06-21"); | ||
const result = getDayOfWeek(date); | ||
expect(result).toBe("Friday"); | ||
}); | ||
|
||
it('should return "Saturday" for date 2024-06-22', () => { | ||
const date = new Date("2024-06-22"); | ||
const result = getDayOfWeek(date); | ||
expect(result).toBe("Saturday"); | ||
}); | ||
|
||
it('should return "Sunday" for date 2024-06-23', () => { | ||
const date = new Date("2024-06-23"); | ||
const result = getDayOfWeek(date); | ||
expect(result).toBe("Sunday"); | ||
}); | ||
|
||
it('should return "Monday" for date 2024-06-24', () => { | ||
const date = new Date("2024-06-24"); | ||
const result = getDayOfWeek(date); | ||
expect(result).toBe("Monday"); | ||
}); | ||
|
||
it('should return "Tuesday" for date 2024-06-25', () => { | ||
const date = new Date("2024-06-25"); | ||
const result = getDayOfWeek(date); | ||
expect(result).toBe("Tuesday"); | ||
}); | ||
}); |
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 |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import { NotificationType } from "@prisma/client"; | ||
import { getNotificationsMessage } from "../../../src/utils/notificationsMessages"; | ||
|
||
describe("getNotificationsMessage function", () => { | ||
const name = "JohnDoe"; | ||
|
||
it("should return a random message for STREAM_STARTED", () => { | ||
const result = getNotificationsMessage( | ||
NotificationType.STREAM_STARTED, | ||
name | ||
); | ||
const possibleMessages = [ | ||
`Heads up! ${name} is live now. Join the stream and enjoy!`, | ||
`Tune in now! ${name} has just started streaming. Don’t miss out!`, | ||
`Alert! ${name} is live. Catch all the live action now!`, | ||
`${name} is streaming live. Click to join and watch the show!` | ||
]; | ||
expect(possibleMessages).toContain(result); | ||
}); | ||
|
||
it("should return a random message for REWARD_RECEIVED", () => { | ||
const result = getNotificationsMessage( | ||
NotificationType.REWARD_RECEIVED, | ||
name | ||
); | ||
const possibleMessages = [ | ||
`You've received a reward from ${name}! Thanks for creating awesome content!`, | ||
`Amazing! ${name} just sent you a reward. Keep up the great work!`, | ||
`Wow! ${name} has rewarded you for your stream. Thank you for your efforts!`, | ||
`You've been rewarded by ${name}! Your content is truly appreciated.` | ||
]; | ||
expect(possibleMessages).toContain(result); | ||
}); | ||
|
||
it("should return a random message for NEW_FOLLOWER", () => { | ||
const result = getNotificationsMessage(NotificationType.NEW_FOLLOWER, name); | ||
const possibleMessages = [ | ||
`${name} is now following you! Welcome them to your community.`, | ||
`Exciting news! ${name} just followed you. Say hello!`, | ||
`You have a new follower: ${name}. Thanks for growing your community!`, | ||
`${name} has joined your follower list. Keep engaging with your fans!` | ||
]; | ||
expect(possibleMessages).toContain(result); | ||
}); | ||
|
||
it("should return a random message for ACHIEVEMENT_RECEIVED", () => { | ||
const result = getNotificationsMessage( | ||
NotificationType.ACHIEVEMENT_RECEIVED, | ||
name | ||
); | ||
const possibleMessages = [ | ||
`Fantastic! You've unlocked the ${name} achievement. Well done!`, | ||
`Achievement unlocked! You’ve earned ${name}. Keep it up!`, | ||
`Congrats! You've achieved ${name}. Your dedication is paying off!`, | ||
`You've earned the ${name} achievement. Great job and keep striving!` | ||
]; | ||
expect(possibleMessages).toContain(result); | ||
}); | ||
}); |
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 |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { RewardType } from "@prisma/client"; | ||
import { rewards } from "../../../src/utils/rewards"; | ||
|
||
describe("Rewards", () => { | ||
it("should match the expected structure and values", () => { | ||
const expectedRewards: { | ||
[Key in RewardType]: { points: number; cost: number }; | ||
} = { | ||
popsicle: { points: 1, cost: 1 }, | ||
pizza: { points: 2, cost: 4 }, | ||
gift: { points: 5, cost: 10 }, | ||
rocket: { points: 10, cost: 20 }, | ||
star: { points: 25, cost: 50 }, | ||
cake: { points: 50, cost: 99 }, | ||
crown: { points: 75, cost: 150 }, | ||
heart: { points: 100, cost: 180 }, | ||
bouquet: { points: 200, cost: 380 }, | ||
lucky_cat: { points: 1000, cost: 1500 } | ||
}; | ||
|
||
expect(rewards).toEqual(expectedRewards); | ||
}); | ||
}); |