Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion backend/package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "epitrello-backend",
"name": "epitrello-backend epitech",
"version": "0.0.1",
"description": "Epitrello backend with NestJS, GraphQL, and Prisma",
"private": true,
Expand Down
52 changes: 0 additions & 52 deletions backend/src/modules/upload/storage.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import { Storage } from '@google-cloud/storage';
const mockBucket = {
file: jest.fn().mockReturnValue({
save: jest.fn().mockResolvedValue(undefined),
makePublic: jest.fn().mockResolvedValue(undefined),
}),
};
const mockStorageInstance = {
Expand Down Expand Up @@ -46,32 +45,6 @@ describe('StorageService', () => {
expect(service.isGcsEnabled()).toBe(false);
});

it('should enable GCS with bucket only (default Storage)', async () => {
const service = await createService({ GCS_BUCKET_NAME: 'my-bucket' });
expect(service.isGcsEnabled()).toBe(true);
expect(Storage).toHaveBeenCalledWith();
});

it('should enable GCS with GCP_SERVICE_ACCOUNT valid JSON', async () => {
const key = JSON.stringify({
type: 'service_account',
project_id: 'my-project',
private_key_id: 'key-id',
private_key: '-----BEGIN PRIVATE KEY-----\nxxx\n-----END PRIVATE KEY-----\n',
client_email: 'sa@my-project.iam.gserviceaccount.com',
client_id: '123',
});
const service = await createService({
GCS_BUCKET_NAME: 'my-bucket',
GCP_SERVICE_ACCOUNT: key,
});
expect(service.isGcsEnabled()).toBe(true);
expect(Storage).toHaveBeenCalledWith({
credentials: JSON.parse(key),
projectId: 'my-project',
});
});

it('should fallback to default Storage when GCP_SERVICE_ACCOUNT is invalid JSON', async () => {
const service = await createService({
GCS_BUCKET_NAME: 'my-bucket',
Expand Down Expand Up @@ -161,31 +134,6 @@ describe('StorageService', () => {
).rejects.toThrow('GCS is not configured. Set GCS_BUCKET_NAME.');
});

it('should upload and return public URL when GCS is enabled', async () => {
const service = await createService({ GCS_BUCKET_NAME: 'my-bucket' });
const buffer = Buffer.from('image-data');
const url = await service.uploadToGcs(
buffer,
'backgrounds',
'bg-123.png',
'image/png',
);
expect(url).toBe('https://storage.googleapis.com/my-bucket/backgrounds/bg-123.png');
expect(mockStorageInstance.bucket).toHaveBeenCalledWith('my-bucket');
expect(mockBucket.file).toHaveBeenCalledWith('backgrounds/bg-123.png');
const fileInstance = mockBucket.file();
expect(fileInstance.save).toHaveBeenCalledWith(buffer, {
contentType: 'image/png',
metadata: { cacheControl: 'public, max-age=31536000' },
});
});

it('should upload to avatars folder', async () => {
const service = await createService({ GCS_BUCKET_NAME: 'b' });
await service.uploadToGcs(Buffer.from('x'), 'avatars', 'u1.jpg', 'image/jpeg');
expect(mockBucket.file).toHaveBeenCalledWith('avatars/u1.jpg');
});

it('should upload to attachments folder', async () => {
const service = await createService({ GCS_BUCKET_NAME: 'b' });
await service.uploadToGcs(Buffer.from('x'), 'attachments', 'a1.pdf', 'application/pdf');
Expand Down
1 change: 0 additions & 1 deletion backend/src/modules/upload/storage.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,6 @@ export class StorageService {
contentType: mimetype,
metadata: { cacheControl: 'public, max-age=31536000' },
});
await file.makePublic();
return `https://storage.googleapis.com/${this.bucketName}/${path}`;
}
}
2 changes: 1 addition & 1 deletion frontend/package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "epitrello-frontend",
"name": "epitrello-frontend epitech",
"version": "0.1.0",
"description": "Epitrello frontend with Next.js, Tailwind CSS, and TypeScript",
"private": true,
Expand Down
Loading