feat(core): add mock implementations (users, articles, auth, telemetry)
This commit is contained in:
@@ -0,0 +1,46 @@
|
||||
import { injectable } from "inversify";
|
||||
|
||||
import type { IArticlesRepository } from "@/application/repositories/articles.repository.interface.js";
|
||||
import type { Article } from "@/entities/models/article.js";
|
||||
|
||||
@injectable()
|
||||
export class MockArticlesRepository implements IArticlesRepository {
|
||||
private _articles: Article[] = [];
|
||||
|
||||
async getArticle(id: string): Promise<Article | undefined> {
|
||||
return this._articles.find((a) => a.id === id);
|
||||
}
|
||||
|
||||
async getArticles(options?: {
|
||||
status?: string;
|
||||
authorId?: string;
|
||||
limit?: number;
|
||||
offset?: number;
|
||||
}): Promise<Article[]> {
|
||||
let result = [...this._articles];
|
||||
if (options?.status) {
|
||||
result = result.filter((a) => a.status === options.status);
|
||||
}
|
||||
if (options?.authorId) {
|
||||
result = result.filter((a) => a.authorId === options.authorId);
|
||||
}
|
||||
const offset = options?.offset ?? 0;
|
||||
const limit = options?.limit ?? 50;
|
||||
return result.slice(offset, offset + limit);
|
||||
}
|
||||
|
||||
async createArticle(input: Article): Promise<Article> {
|
||||
this._articles.push(input);
|
||||
return input;
|
||||
}
|
||||
|
||||
async updateArticle(
|
||||
id: string,
|
||||
input: Partial<Article>
|
||||
): Promise<Article | undefined> {
|
||||
const index = this._articles.findIndex((a) => a.id === id);
|
||||
if (index === -1) return undefined;
|
||||
this._articles[index] = { ...this._articles[index]!, ...input };
|
||||
return this._articles[index];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
import { injectable } from "inversify";
|
||||
|
||||
import type { IUsersRepository } from "@/application/repositories/users.repository.interface.js";
|
||||
import type { User } from "@/entities/models/user.js";
|
||||
|
||||
@injectable()
|
||||
export class MockUsersRepository implements IUsersRepository {
|
||||
private _users: User[] = [
|
||||
{ id: "1", username: "alice", passwordHash: "hashed_password_alice" },
|
||||
{ id: "2", username: "bob", passwordHash: "hashed_password_bob" },
|
||||
];
|
||||
|
||||
async getUser(id: string): Promise<User | undefined> {
|
||||
return this._users.find((u) => u.id === id);
|
||||
}
|
||||
|
||||
async getUserByUsername(username: string): Promise<User | undefined> {
|
||||
return this._users.find((u) => u.username === username);
|
||||
}
|
||||
|
||||
async createUser(input: User): Promise<User> {
|
||||
this._users.push(input);
|
||||
return input;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user