Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
99 commits
Select commit Hold shift + click to select a range
5c2b237
chore: add lazy loading to images
elinejaa Nov 6, 2026
958eca2
refactor: move review form into reusable ReviewComposer component
Nov 6, 2026
16686d6
feat: add paginated userReviews and Count queries
Nov 6, 2026
0e7cd71
feat: add your reviews loading function
Nov 6, 2026
69e3623
feat: add collapsing review cards and change stars placement
Nov 6, 2026
9f01f82
feat: add a "your reviews" section to profile page
Nov 6, 2026
70b78a0
chore: update images to webp
elinejaa Nov 6, 2026
1146d31
test: add tests for your reviews changes
Nov 6, 2026
4236c42
fix: stop passive game card flicker on hover
Nov 6, 2026
e0ef4cf
feat: add original game price when discounted
Nov 6, 2026
f9e48c2
test: add tests for original and discounted prices
Nov 6, 2026
c417e7b
test: e2e setup
carmennt Nov 9, 2026
52b2383
test: tests
carmennt Nov 9, 2026
c59d831
fix: making tests almost run
carmennt Nov 9, 2026
993266f
fix: remove .env.e2e
carmennt Nov 9, 2026
44b56fd
test: e2e setup
carmennt Nov 9, 2026
022dc67
test: tests
carmennt Nov 9, 2026
882268a
fix: making tests almost run
carmennt Nov 9, 2026
17a4b0d
fix: remove .env.e2e
carmennt Nov 9, 2026
c5c7eb2
Merge branch 'end-to-end-and-api-testing' of https://git.ntnu.no/IT28…
carmennt Nov 9, 2026
0730099
test: matching test to actual pages
carmennt Nov 9, 2026
faabf4c
test: Tests run like they should
carmennt Nov 10, 2026
bbd5665
feat: e2e coverage
carmennt Nov 10, 2026
a17e064
refactor: move review form into reusable ReviewComposer component
Nov 6, 2026
7d6d1d7
feat: add paginated userReviews and Count queries
Nov 6, 2026
ce7cf40
feat: add your reviews loading function
Nov 6, 2026
fe39f2a
feat: add collapsing review cards and change stars placement
Nov 6, 2026
433e6d3
feat: add a "your reviews" section to profile page
Nov 6, 2026
b743da6
test: add tests for your reviews changes
Nov 6, 2026
96f0d9c
fix: stop passive game card flicker on hover
Nov 6, 2026
4cb77dd
feat: add original game price when discounted
Nov 6, 2026
ef6ffd4
test: add tests for original and discounted prices
Nov 6, 2026
0e5f5e0
Merge branch 'create-your-reviews' of https://git.ntnu.no/IT2810-H26/…
Nov 10, 2026
aa4e125
fix: remove duplicated review composer styles from ActiveGameCard.css
Nov 10, 2026
d384e60
Merge branch 'create-your-reviews' of https://git.ntnu.no/IT2810-H26/…
Nov 10, 2026
964d041
feat: implement dynamic loading games on profile
elinejaa Nov 10, 2026
86a63e7
chore: update env file placement
elinejaa Nov 10, 2026
adb0b91
feat: make debounced value hook
elinejaa Nov 10, 2026
d581bc7
Merge branch 'main' of https://git.ntnu.no/IT2810-H26/T10-Project-2 i…
Nov 10, 2026
e1654b3
style: remove redundant import
elinejaa Nov 10, 2026
11c269a
Merge branch 'main' into 93-performance-enhancements
elinejaa Nov 10, 2026
46a1cd6
Merge branch 'create-your-reviews' of https://git.ntnu.no/IT2810-H26/…
carmennt Nov 10, 2026
049c1c6
Merge pull request #103 from IT2810-H26/create-your-reviews
elinejaa Nov 10, 2026
323ddc4
test: update failed test
elinejaa Nov 10, 2026
0353755
feat: update games grid to fetch only when new games searched
elinejaa Nov 10, 2026
b58b2da
feat: move logic out of searchpage
elinejaa Nov 10, 2026
44c2bed
Merge branch 'main' into 93-performance-enhancements
elinejaa Nov 10, 2026
dbd4d00
style: remove redundant linespace
elinejaa Nov 10, 2026
d3e0eab
style: remove redundant linespace
elinejaa Nov 10, 2026
359de6e
feat: add error message when server can't be reached
Nov 10, 2026
116eb1a
fix: load errors inside section without duplicates
Nov 10, 2026
0bbb0d5
fix: fix friend and card error placements
Nov 10, 2026
2510853
Merge pull request #108 from IT2810-H26/93-performance-enhancements
catrinjo Nov 10, 2026
43dcd16
Merge branch 'main' of https://git.ntnu.no/IT2810-H26/T10-Project-2 i…
Nov 10, 2026
14c91f5
merge
Nov 10, 2026
bc21e13
fix: show loading errors without duplicate for search and filter
Nov 10, 2026
b1bdbdf
fix: show readable error when cannot reach server
Nov 10, 2026
9a27e16
chore: remove unused imports
Nov 10, 2026
baa4bea
fix: remove lengthy error message text
Nov 10, 2026
5f02b40
test: e2e setup
carmennt Nov 9, 2026
223b17e
test: tests
carmennt Nov 9, 2026
5a45a93
fix: making tests almost run
carmennt Nov 9, 2026
244d42b
fix: remove .env.e2e
carmennt Nov 9, 2026
ba99bfd
test: e2e setup
carmennt Nov 9, 2026
4fd4c8e
fix: remove .env.e2e
carmennt Nov 9, 2026
7c8fb5c
test: matching test to actual pages
carmennt Nov 9, 2026
698dbca
test: Tests run like they should
carmennt Nov 10, 2026
aa84486
feat: e2e coverage
carmennt Nov 10, 2026
9cee4bf
Merge branch 'end-to-end-and-api-testing' of https://git.ntnu.no/IT28…
carmennt Nov 12, 2026
88cde28
fix: adding fill genres to test database
carmennt Nov 12, 2026
31b7965
fix: update tests to match new search functionality
carmennt Nov 12, 2026
612b529
feat: mobile tests
carmennt Nov 12, 2026
d652ca1
feat: api tests
carmennt Nov 12, 2026
f97ffff
Merge pull request #110 from IT2810-H26/error-handling
carmennt Nov 12, 2026
103de33
test: e2e setup
carmennt Nov 9, 2026
e7d7b04
test: tests
carmennt Nov 9, 2026
baf1dc9
fix: making tests almost run
carmennt Nov 9, 2026
d241eaf
fix: remove .env.e2e
carmennt Nov 9, 2026
b5aa5f8
test: e2e setup
carmennt Nov 9, 2026
b75bf35
fix: remove .env.e2e
carmennt Nov 9, 2026
c60d4f7
test: matching test to actual pages
carmennt Nov 9, 2026
ef1aebd
test: Tests run like they should
carmennt Nov 10, 2026
53c3300
feat: e2e coverage
carmennt Nov 10, 2026
7893a13
test: e2e setup
carmennt Nov 9, 2026
91ab3de
fix: making tests almost run
carmennt Nov 9, 2026
5d63df4
test: e2e setup
carmennt Nov 9, 2026
eed195e
test: tests
carmennt Nov 9, 2026
e0ab53f
test: matching test to actual pages
carmennt Nov 9, 2026
bef5d8b
test: Tests run like they should
carmennt Nov 10, 2026
6a66a4e
feat: e2e coverage
carmennt Nov 10, 2026
102eacf
fix: adding fill genres to test database
carmennt Nov 12, 2026
3409444
fix: update tests to match new search functionality
carmennt Nov 12, 2026
2799e10
feat: mobile tests
carmennt Nov 12, 2026
a462700
feat: api tests
carmennt Nov 12, 2026
f94f52b
Merge branch 'end-to-end-and-api-testing' of https://git.ntnu.no/IT28…
carmennt Nov 12, 2026
29ce910
fix: merge cleanup
carmennt Nov 12, 2026
cfdfde9
test: all tests run
carmennt Nov 12, 2026
f679074
fix: package update and formatting
elinejaa Nov 13, 2026
4221cea
fix: extra fallback handeling and deleting workflow
carmennt Nov 13, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,12 @@ Coverage/

#Env file
.env
.env.development
.env.development

# Playwright
/test-results/
/playwright-report/
/blob-report/
/playwright/.cache/
/playwright/.auth/
playwright-report-api/
2 changes: 2 additions & 0 deletions Backend/Schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ export const typeDefs = `#graphql
discountedGames(genre: String!): [Game!]!
reviews(gameId: Int!, userId: Int): [Review!]!
recentReviews(limit: Int = 10): [Review!]!
userReviews(userId: Int!, limit: Int = 6, offset: Int = 0): [Review!]!
userReviewCount(userId: Int!): Int!
friends(userId: Int!): [Friend!]!
friendWishlist(userId: Int!, friendId: Int!): [Game!]!
myFriendId(userId: Int!): String
Expand Down
9 changes: 8 additions & 1 deletion Backend/Server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,19 @@ import { typeDefs } from './Schema.ts'
import { resolvers } from './resolvers/index.ts'

const server = new ApolloServer({ typeDefs, resolvers })

const port = Number(process.env.PORT ?? 3001)

const { url } = await startStandaloneServer(server, {
listen: { host: process.env.HOST ?? '127.0.0.1', port: 3001 },
listen: {
host: process.env.HOST ?? '127.0.0.1',
port
},
context: async ({ req }) => ({
token: req.headers.authorization?.replace(/^Bearer /, '') ?? null
})
})

console.log(
`Database: ${process.env.DB_USER}@${process.env.DB_HOST}:${process.env.DB_PORT}/${process.env.DB_NAME}`
)
Expand Down
44 changes: 36 additions & 8 deletions Backend/logic/ReviewsLogicBackend.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,17 @@ function ValidateId(id: number, name: string) {
if (!Number.isSafeInteger(id) || id <= 0) throw new Error(`The ${name} is invalid.`)
}

function ClampLimit(limit: number): number {
return Math.min(Math.max(Math.trunc(limit) || 1, 1), 50)
}

const REVIEWS_WITH_GAME_NAME = `
SELECT ${REVIEW_COLUMNS},
g.game_name AS "gameName"
FROM reviews r
JOIN users u ON u.user_id = r.user_id
JOIN games g ON g.game_id = r.game_id`

export async function GetReviewsForGame(
gameId: number,
currentUserId: number | null = null
Expand All @@ -47,21 +58,38 @@ export async function GetReviewsForGame(
}

export async function GetRecentReviews(limit = 10): Promise<Review[]> {
const safeLimit = Math.min(Math.max(Math.trunc(limit) || 1, 1), 50)

const { rows } = await pool.query(
`SELECT ${REVIEW_COLUMNS},
g.game_name AS "gameName"
FROM reviews r
JOIN users u ON u.user_id = r.user_id
JOIN games g ON g.game_id = r.game_id
`${REVIEWS_WITH_GAME_NAME}
ORDER BY r.review_id DESC
LIMIT $1`,
[safeLimit]
[ClampLimit(limit)]
)
return rows
}

export async function GetReviewsByUser(userId: number, limit = 6, offset = 0): Promise<Review[]> {
ValidateId(userId, 'user ID')
const safeOffset = Math.max(Math.trunc(offset) || 0, 0)

const { rows } = await pool.query(
`${REVIEWS_WITH_GAME_NAME}
WHERE r.user_id = $1
ORDER BY r.review_id DESC
LIMIT $2 OFFSET $3`,
[userId, ClampLimit(limit), safeOffset]
)
return rows
}

export async function CountReviewsByUser(userId: number): Promise<number> {
ValidateId(userId, 'user ID')

const { rows } = await pool.query('SELECT COUNT(*) AS count FROM reviews WHERE user_id = $1', [
userId
])
return Number(rows[0].count)
}

export async function CreateReview(
userId: number,
gameId: number,
Expand Down
7 changes: 5 additions & 2 deletions Backend/logic/UserLogicBackend.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,11 @@ export async function RequireUser(token: string | null, userId: number | null):
})
}
const { rows } = await pool.query('SELECT user_id FROM users WHERE token = $1', [token])
if (rows.length === 0 || rows[0].user_id !== userId) {
throw new GraphQLError('Not allowed.', { extensions: { code: 'FORBIDDEN' } })

if (rows.length === 0 || Number(rows[0].user_id) !== Number(userId)) {
throw new GraphQLError('Not allowed.', {
extensions: { code: 'FORBIDDEN' }
})
}
}

Expand Down
12 changes: 11 additions & 1 deletion Backend/resolvers/ReviewResolvers.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import {
CountReviewsByUser,
CreateReview,
DeleteReview,
GetRecentReviews,
GetReviewsByUser,
GetReviewsForGame,
UpdateReview
} from '../logic/ReviewsLogicBackend.ts'
Expand All @@ -12,7 +14,15 @@ export const reviewQueryResolvers = {
reviews: (_parent: unknown, { gameId, userId }: { gameId: number; userId?: number | null }) =>
GetReviewsForGame(gameId, userId ?? null),

recentReviews: (_parent: unknown, { limit }: { limit: number }) => GetRecentReviews(limit)
recentReviews: (_parent: unknown, { limit }: { limit: number }) => GetRecentReviews(limit),

userReviews: (
_parent: unknown,
{ userId, limit, offset }: { userId: number; limit: number; offset: number }
) => GetReviewsByUser(userId, limit, offset),

userReviewCount: (_parent: unknown, { userId }: { userId: number }) =>
CountReviewsByUser(userId)
}

export const reviewMutationResolvers = {
Expand Down
46 changes: 46 additions & 0 deletions Backend/tests/GameResolvers.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
// @vitest-environment node
import { beforeEach, describe, expect, it, vi } from 'vitest'

const { Query } = vi.hoisted(() => ({ Query: vi.fn() }))

vi.mock('../DatabaseConnection.ts', () => ({ pool: { query: Query } }))

import { gameQueryResolvers } from '../resolvers/GameResolvers.ts'

beforeEach(() => {
Query.mockReset()
})

describe('games resolver search', () => {
it('filters by name and returns the requested page', async () => {
const games = [{ appid: 570, name: 'Dota 2' }]
Query.mockResolvedValue({ rows: games })

const result = await gameQueryResolvers.games(null, {
search: 'dota',
limit: 20,
offset: 20
})

expect(result).toEqual(games)
expect(Query.mock.calls[0][0]).toContain('g.game_name ILIKE $1')
expect(Query.mock.calls[0][0]).toContain('LIMIT $4 OFFSET $5')
expect(Query.mock.calls[0][1].slice(-2)).toEqual([20, 20])
})

it('caps page size at the existing API maximum', async () => {
Query.mockResolvedValue({ rows: [] })

await gameQueryResolvers.games(null, { search: 'game', limit: 1000, offset: 0 })

expect(Query.mock.calls[0][1].slice(-2)).toEqual([500, 0])
})

it('passes database errors through', async () => {
Query.mockRejectedValue(new Error('connection refused'))

await expect(
gameQueryResolvers.games(null, { search: 'game', limit: 20, offset: 0 })
).rejects.toThrow('connection refused')
})
})
55 changes: 55 additions & 0 deletions Backend/tests/ReviewsBackend.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@ const { Query } = vi.hoisted(() => ({ Query: vi.fn() }))
vi.mock('../DatabaseConnection.ts', () => ({ pool: { query: Query } }))

import {
CountReviewsByUser,
CreateReview,
DeleteReview,
GetRecentReviews,
GetReviewsByUser,
GetReviewsForGame,
UpdateReview
} from '../logic/ReviewsLogicBackend.ts'
Expand Down Expand Up @@ -86,6 +88,59 @@ describe('reviews (backend)', () => {
})
})

describe('GetReviewsByUser', () => {
it("returns the first page of one user's reviews with the game names, newest first", async () => {
Query.mockResolvedValue({ rows: [testReview] })

await expect(GetReviewsByUser(7)).resolves.toEqual([testReview])

const [sql, params] = Query.mock.calls[0]
expect(String(sql)).toContain('g.game_name AS "gameName"')
expect(String(sql)).toContain('WHERE r.user_id = $1')
expect(String(sql)).toContain('ORDER BY r.review_id DESC')
expect(String(sql)).toContain('LIMIT $2 OFFSET $3')
expect(params).toEqual([7, 6, 0])
})

it('skips the reviews of earlier pages', async () => {
Query.mockResolvedValue({ rows: [] })

await GetReviewsByUser(7, 6, 12)

expect(Query.mock.calls[0][1]).toEqual([7, 6, 12])
})

it('keeps the page size between 1 and 50 and the offset at 0 or more', async () => {
Query.mockResolvedValue({ rows: [] })

await GetReviewsByUser(7, 1000, -5)

expect(Query.mock.calls[0][1]).toEqual([7, 50, 0])
})

it('rejects an invalid user id without touching the database', async () => {
await expect(GetReviewsByUser(0)).rejects.toThrow('The user ID is invalid.')
expect(Query).not.toHaveBeenCalled()
})
})

describe('CountReviewsByUser', () => {
it('counts all reviews written by the user', async () => {
Query.mockResolvedValue({ rows: [{ count: '13' }] })

await expect(CountReviewsByUser(7)).resolves.toBe(13)

const [sql, params] = Query.mock.calls[0]
expect(String(sql)).toContain('WHERE user_id = $1')
expect(params).toEqual([7])
})

it('rejects an invalid user id without touching the database', async () => {
await expect(CountReviewsByUser(-1)).rejects.toThrow('The user ID is invalid.')
expect(Query).not.toHaveBeenCalled()
})
})

describe('CreateReview', () => {
it('saves the review and returns it with the username', async () => {
Query.mockResolvedValue({ rows: [testReview] })
Expand Down
Loading