Skip to content

Commit 8b9ec54

Browse files
authored
fix: remove file suffix from user CV blob (#2977)
1 parent 8f6d166 commit 8b9ec54

File tree

3 files changed

+22
-37
lines changed

3 files changed

+22
-37
lines changed

__tests__/users.ts

Lines changed: 20 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -115,11 +115,7 @@ import { identifyUserPersonalizedDigest } from '../src/cio';
115115
import type { GQLUser } from '../src/schema/users';
116116
import { cancelSubscription } from '../src/common/paddle';
117117
import { isPlusMember, SubscriptionCycles } from '../src/paddle';
118-
import {
119-
acceptedResumeExtensions,
120-
CoresRole,
121-
StreakRestoreCoresPrice,
122-
} from '../src/types';
118+
import { CoresRole, StreakRestoreCoresPrice } from '../src/types';
123119
import {
124120
UserTransaction,
125121
UserTransactionProcessor,
@@ -4393,13 +4389,10 @@ describe('mutation deleteUser', () => {
43934389
await client.mutate(MUTATION);
43944390

43954391
// Verify we requested delete action for every extension supported
4396-
acceptedResumeExtensions.forEach((ext, index) => {
4397-
expect(deleteFileFromBucket).toHaveBeenNthCalledWith(
4398-
index + 1,
4399-
expect.any(Bucket),
4400-
`${loggedUser}.${ext}`,
4401-
);
4402-
});
4392+
expect(deleteFileFromBucket).toHaveBeenCalledWith(
4393+
expect.any(Bucket),
4394+
loggedUser,
4395+
);
44034396
});
44044397

44054398
it('should handle case when user has no resume', async () => {
@@ -4410,13 +4403,10 @@ describe('mutation deleteUser', () => {
44104403
await client.mutate(MUTATION);
44114404

44124405
// Verify the function was called but no error was thrown
4413-
acceptedResumeExtensions.forEach((ext, index) => {
4414-
expect(deleteFileFromBucket).toHaveBeenNthCalledWith(
4415-
index + 1,
4416-
expect.any(Bucket),
4417-
`${loggedUser}.${ext}`,
4418-
);
4419-
});
4406+
expect(deleteFileFromBucket).toHaveBeenCalledWith(
4407+
expect.any(Bucket),
4408+
loggedUser,
4409+
);
44204410

44214411
// User should still be deleted
44224412
const userOne = await con.getRepository(User).findOneBy({ id: '1' });
@@ -6785,13 +6775,13 @@ describe('add claimable items to user', () => {
67856775
});
67866776

67876777
describe('mutation uploadResume', () => {
6788-
const MUTATION = `
6789-
mutation UploadResume($resume: Upload!) {
6790-
uploadResume(resume: $resume) {
6791-
_
6792-
}
6793-
}
6794-
`;
6778+
const MUTATION = /* GraphQL */ `
6779+
mutation UploadResume($resume: Upload!) {
6780+
uploadResume(resume: $resume) {
6781+
_
6782+
}
6783+
}
6784+
`;
67956785

67966786
beforeEach(async () => {
67976787
jest.clearAllMocks();
@@ -6832,7 +6822,7 @@ describe('mutation uploadResume', () => {
68326822

68336823
// Mock the upload function to return a URL
68346824
uploadResumeFromBuffer.mockResolvedValue(
6835-
`https://storage.cloud.google.com/${RESUMES_BUCKET_NAME}/1.pdf`,
6825+
`https://storage.cloud.google.com/${RESUMES_BUCKET_NAME}/1`,
68366826
);
68376827

68386828
// Execute the mutation with a file upload
@@ -6857,7 +6847,7 @@ describe('mutation uploadResume', () => {
68576847

68586848
// Verify the mocks were called correctly
68596849
expect(uploadResumeFromBuffer).toHaveBeenCalledWith(
6860-
`${loggedUser}.pdf`,
6850+
loggedUser,
68616851
expect.any(Object),
68626852
);
68636853
});
@@ -6873,7 +6863,7 @@ describe('mutation uploadResume', () => {
68736863

68746864
// Mock the upload function to return a URL
68756865
uploadResumeFromBuffer.mockResolvedValue(
6876-
`https://storage.cloud.google.com/${RESUMES_BUCKET_NAME}/1.docx`,
6866+
`https://storage.cloud.google.com/${RESUMES_BUCKET_NAME}/1`,
68776867
);
68786868

68796869
// Execute the mutation with a file upload
@@ -6898,7 +6888,7 @@ describe('mutation uploadResume', () => {
68986888

68996889
// Verify the mocks were called correctly
69006890
expect(uploadResumeFromBuffer).toHaveBeenCalledWith(
6901-
`${loggedUser}.docx`,
6891+
loggedUser,
69026892
expect.any(Object),
69036893
);
69046894
});

src/common/googleCloud.ts

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -99,12 +99,7 @@ export const deleteResumeByUserId = async (
9999
const storage = new Storage();
100100
const bucket = storage.bucket(bucketName);
101101

102-
await Promise.all(
103-
// delete all possible accepted {id}.{ext} files uploaded by the user
104-
acceptedResumeExtensions.map((ext) =>
105-
deleteFileFromBucket(bucket, `${userId}.${ext}`),
106-
),
107-
);
102+
await deleteFileFromBucket(bucket, userId);
108103

109104
logger.info(
110105
{

src/schema/users.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2528,7 +2528,7 @@ export const resolvers: IResolvers<unknown, BaseContext> = traceResolvers<
25282528
}
25292529

25302530
// Actual upload using buffer as a stream
2531-
const filename = `${ctx.userId}.${extension}`;
2531+
const filename = ctx.userId;
25322532
await uploadResumeFromBuffer(filename, buffer);
25332533

25342534
return { _: true };

0 commit comments

Comments
 (0)