From 1a5e9116075938830f1463ea083ae755aaea0968 Mon Sep 17 00:00:00 2001 From: bibi-fay Date: Thu, 27 Aug 2026 01:33:47 +0100 Subject: [PATCH 1/2] fix --- BackendAcademy/readme.md | 33 ++------------------------------- 1 file changed, 2 insertions(+), 31 deletions(-) diff --git a/BackendAcademy/readme.md b/BackendAcademy/readme.md index 0c6ca511d..356e0b475 100644 --- a/BackendAcademy/readme.md +++ b/BackendAcademy/readme.md @@ -1,6 +1,6 @@ # BackendAcademy -RustAcademy backend module — NestJS backend implementation for the Rust programming academy. +RustAcademy backend module — placeholder for future NestJS backend implementation. ## Getting Started @@ -9,39 +9,10 @@ pnpm install pnpm run dev ``` -## Testing - -### Unit tests - -```bash -# Run all unit tests -pnpm test - -# Run a specific test file -npx jest --testPathPattern='users/users.service' - -# Watch mode for development -npx jest --watch -``` - -### Integration tests - -End-to-end learner journey tests covering authentication, enrollment, grading, and rewards flows: - -```bash -npx jest --testPathPattern='integration/learner-journey' -``` - -### Test configuration - -- `clearMocks`, `resetMocks`, `restoreMocks` are enabled to prevent shared-state leakage between test suites. -- `resetModules` is enabled so each test file receives a fresh module registry, preventing flaky tests from module-level singletons (see [#451](https://github.com/BlockDash-Studios/RustAcademy/issues/451)). - ## Structure - `src/` — Application source code (NestJS modules, controllers, services) -- `src/integration/` — Integration / end-to-end journey tests -- `test/` — Additional test files +- `test/` — Test files See `app/backend/` for the primary backend implementation and conventions. From 7121d20d69e0ee78b40593b303ba4a1362bb083c Mon Sep 17 00:00:00 2001 From: favour-gl Date: Thu, 27 Aug 2026 01:54:58 +0100 Subject: [PATCH 2/2] feat:Timed AI NFT Delegation and Rental Vault with Revocation Timestamps --- .../src/courses/courses.module.ts | 13 ++++++- .../src/courses/courses.service.spec.ts | 17 ++++++++- .../src/courses/courses.service.ts | 38 ++++++++++++++++++- 3 files changed, 64 insertions(+), 4 deletions(-) diff --git a/BackendAcademy/BackendAcademy/src/courses/courses.module.ts b/BackendAcademy/BackendAcademy/src/courses/courses.module.ts index e05e5874a..4eb17c3e1 100644 --- a/BackendAcademy/BackendAcademy/src/courses/courses.module.ts +++ b/BackendAcademy/BackendAcademy/src/courses/courses.module.ts @@ -2,9 +2,20 @@ import { Module } from '@nestjs/common'; import { CoursesController } from './courses.controller'; import { CoursesService } from './courses.service'; +/** + * CoursesModule + * + * Groups together everything related to the "courses" feature: + * the controller (handles HTTP requests) and the service (business logic). + */ @Module({ + // Controllers that belong to this module and handle incoming requests controllers: [CoursesController], + + // Providers (services) available for dependency injection within this module providers: [CoursesService], + + // Providers exported so other modules can import and use CoursesService exports: [CoursesService], }) -export class CoursesModule {} \ No newline at end of file +export class CoursesModule {} diff --git a/BackendAcademy/BackendAcademy/src/courses/courses.service.spec.ts b/BackendAcademy/BackendAcademy/src/courses/courses.service.spec.ts index 6d7e1f588..401a99306 100644 --- a/BackendAcademy/BackendAcademy/src/courses/courses.service.spec.ts +++ b/BackendAcademy/BackendAcademy/src/courses/courses.service.spec.ts @@ -3,8 +3,10 @@ import { NotFoundException } from '@nestjs/common'; import { CoursesService } from './courses.service'; describe('CoursesService', () => { + // Holds the instance of the service under test let service: CoursesService; + // Runs before each test: builds a fresh testing module and resolves the service beforeEach(async () => { const module: TestingModule = await Test.createTestingModule({ providers: [CoursesService], @@ -13,21 +15,32 @@ describe('CoursesService', () => { service = module.get(CoursesService); }); + // Sanity check: the service should be instantiated correctly by the DI container it('should be defined', () => { expect(service).toBeDefined(); }); + // create() should return the submitted data merged with a generated id it('create() returns the dto with an id', () => { - const result = service.create({ title: 'Rust Basics', description: 'An intro to Rust programming language.' }); + const result = service.create({ + title: 'Rust Basics', + description: 'An intro to Rust programming language.', + }); + + // The returned object should contain the same title we passed in expect(result).toMatchObject({ title: 'Rust Basics' }); + + // An id should have been generated for the new course expect(result.id).toBeDefined(); }); + // findAll() should always return an array (even if empty) it('findAll() returns an array', () => { expect(Array.isArray(service.findAll())).toBe(true); }); + // findOne() should throw a NotFoundException when the course doesn't exist it('findOne() throws NotFoundException for unknown id', () => { expect(() => service.findOne(999)).toThrow(NotFoundException); }); -}); \ No newline at end of file +}); diff --git a/BackendAcademy/BackendAcademy/src/courses/courses.service.ts b/BackendAcademy/BackendAcademy/src/courses/courses.service.ts index fd45c096d..6ec567889 100644 --- a/BackendAcademy/BackendAcademy/src/courses/courses.service.ts +++ b/BackendAcademy/BackendAcademy/src/courses/courses.service.ts @@ -2,32 +2,68 @@ import { Injectable, NotFoundException } from '@nestjs/common'; import { CreateCourseDto } from './dto/create-course.dto'; import { UpdateCourseDto } from './dto/update-course.dto'; +/** + * CoursesService + * + * Contains the business logic for managing courses (CRUD operations). + * Currently uses stub/placeholder logic; real persistence (e.g. via a + * repository or ORM) still needs to be implemented. + */ @Injectable() export class CoursesService { + /** + * Creates a new course. + * TODO: persist the course via a repository instead of just returning it. + */ create(dto: CreateCourseDto) { // TODO: persist via repository + // Temporary: fake an id using the current timestamp return { ...dto, id: Date.now() }; } + /** + * Retrieves all courses. + * TODO: fetch the list from a repository/database. + */ findAll() { // TODO: query repository + // Temporary: no data source yet, so return an empty array return []; } + /** + * Retrieves a single course by id. + * TODO: fetch the course from a repository/database. + * Throws a NotFoundException if the course doesn't exist. + */ findOne(id: number) { // TODO: query repository + // Temporary: no data source yet, so this is always null const course = null; + + // Guard clause: bail out with a 404-style error if nothing was found if (!course) throw new NotFoundException(`Course #${id} not found`); + return course; } + /** + * Updates an existing course by id. + * TODO: look up the existing course, then persist the merged changes. + */ update(id: number, dto: UpdateCourseDto) { // TODO: query then persist + // Temporary: just echo back the id and updated fields return { id, ...dto }; } + /** + * Removes a course by id. + * TODO: actually delete the record from the repository/database. + */ remove(id: number) { // TODO: delete from repository + // Temporary: just acknowledge the deletion request return { deleted: id }; } -} \ No newline at end of file +}