Skip to content
Merged
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
45 changes: 45 additions & 0 deletions src/app/drive/services/file.service/uploadFile.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,51 @@ describe('Create File Entry', () => {
ownerToken,
);
});

test('When creating a file entry for personal storage and a resources token is present, then the file entry for personal storage should be created using that token', async () => {
const file: FileToUpload = {
name: 'personal-file',
size: 2048,
type: 'txt',
content: new File(['content'], 'personal-file.txt'),
parentFolderId: 'folder-uuid-456',
};
const bucketId = 'personal-bucket';
const fileId = 'personal-file-id';
const resourcesToken = 'resources-token';
const ownerToken = 'owner-token';

const expectedResponse = { id: 'personal-created-id', name: file.name };
const mockCreateFileEntryByUuid = vi.fn().mockResolvedValue(expectedResponse);
mockSdkFactory.getNewApiInstance.mockReturnValue({
createNewStorageClient: vi.fn(() => ({
createFileEntryByUuid: mockCreateFileEntryByUuid,
})),
} as any);

const result = await createFileEntry({
bucketId,
fileId,
file,
isWorkspaceUpload: false,
resourcesToken,
ownerToken,
});

expect(result).toEqual(expectedResponse);
expect(mockCreateFileEntryByUuid).toHaveBeenCalledWith(
expect.objectContaining({
fileId: fileId,
type: file.type,
size: file.size,
plainName: file.name,
bucket: bucketId,
folderUuid: file.parentFolderId,
encryptVersion: StorageTypes.EncryptionVersion.Aes03,
}),
resourcesToken,
);
});
});

describe('Uploading a file', () => {
Expand Down
2 changes: 1 addition & 1 deletion src/app/drive/services/file.service/uploadFile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ export const createFileEntry = async ({
date: date.toISOString(),
};

return storageClient.createFileEntryByUuid(fileEntry, ownerToken);
return storageClient.createFileEntryByUuid(fileEntry, resourcesToken ?? ownerToken);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jzunigax2 update the tests, it is very delicate change that can break the upload.
Add also description and what need to tests :)
Thanks!

}
};

Expand Down
2 changes: 2 additions & 0 deletions src/views/Shared/SharedView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -405,6 +405,7 @@ function SharedView({
encryptionKey: currentUser?.mnemonic,
bucketId: currentUser.bucket,
token,
resourcesToken: token,
};
} else {
const mnemonicDecrypted =
Expand All @@ -416,6 +417,7 @@ function SharedView({
encryptionKey: mnemonicDecrypted,
bucketId: ownerBucket,
token,
resourcesToken: token,
};
}
}
Expand Down
Loading