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
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@internxt/sdk",
"author": "Internxt <hello@internxt.com>",
"version": "1.21.0",
"version": "1.21.1",
"description": "An sdk for interacting with Internxt's services",
"repository": {
"type": "git",
Expand Down
6 changes: 4 additions & 2 deletions src/drive/storage/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -864,7 +864,8 @@ export class Storage {
* @returns {Promise<FolderMeta>} A promise that resolves the folder on that path.
*/
public getFolderByPath(folderPath: string): Promise<FolderMeta> {
return this.client.get<FolderMeta>(`folders/meta?path=${folderPath}`, this.headers());
const query = new URLSearchParams({ path: folderPath });
return this.client.get<FolderMeta>(`folders/meta?${query}`, this.headers());
}

/**
Expand All @@ -874,7 +875,8 @@ export class Storage {
* @returns {Promise<FileMeta>} A promise that resolves the file on that path.
*/
public getFileByPath(filePath: string): Promise<FileMeta> {
return this.client.get<FileMeta>(`files/meta?path=${filePath}`, this.headers());
const query = new URLSearchParams({ path: filePath });
return this.client.get<FileMeta>(`files/meta?${query}`, this.headers());
}

/**
Expand Down
71 changes: 71 additions & 0 deletions test/drive/storage/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,15 @@ import { randomMoveFolderPayload } from './mothers/moveFolderPayload.mother';
import { randomUpdateFolderMetadataPayload } from './mothers/updateFolderMetadataPayload.mother';

describe('# storage service tests', () => {
const pathEncodingCases = [
['/report 50%.txt', '%2Freport+50%25.txt'],
['/a&b/c#d.txt', '%2Fa%26b%2Fc%23d.txt'],
['/tom+jerry/note.txt', '%2Ftom%2Bjerry%2Fnote.txt'],
['/literal%2Fescape.txt', '%2Fliteral%252Fescape.txt'],
['/ñ émoji 🎉.txt', '%2F%C3%B1+%C3%A9moji+%F0%9F%8E%89.txt'],
['/plain/path.txt', '%2Fplain%2Fpath.txt'],
];

beforeEach(() => {
vi.restoreAllMocks();
});
Expand Down Expand Up @@ -481,6 +490,37 @@ describe('# storage service tests', () => {
expect(body).toEqual(mockResponse);
});
});

describe('get folder by path', () => {
it('When a folder path is provided then it should be sent as an encoded query param', async () => {
// Arrange
const response = { uuid: 'folder-uuid' };
const callStub = vi.spyOn(HttpClient.prototype, 'get').mockResolvedValue(response);
const { client, headers } = clientAndHeaders({});

// Act
const body = await client.getFolderByPath('/folder1/folder2');

// Assert
expect(callStub).toHaveBeenCalledWith('folders/meta?path=%2Ffolder1%2Ffolder2', headers);
expect(body).toEqual(response);
});

it.each(pathEncodingCases)(
'When the folder path is %j then it should encode it as %s',
async (folderPath, encodedPath) => {
// Arrange
const callStub = vi.spyOn(HttpClient.prototype, 'get').mockResolvedValue({});
const { client, headers } = clientAndHeaders({});

// Act
await client.getFolderByPath(folderPath);

// Assert
expect(callStub).toHaveBeenCalledWith(`folders/meta?path=${encodedPath}`, headers);
},
);
});
});

describe('-> files', () => {
Expand Down Expand Up @@ -724,6 +764,37 @@ describe('# storage service tests', () => {
expect(body).toEqual(response);
});
});

describe('get file by path', () => {
it('When a file path is provided then it should be sent as an encoded query param', async () => {
// Arrange
const response = randomFileMetaData();
const callStub = vi.spyOn(HttpClient.prototype, 'get').mockResolvedValue(response);
const { client, headers } = clientAndHeaders({});

// Act
const body = await client.getFileByPath('/folder1/file.png');

// Assert
expect(callStub).toHaveBeenCalledWith('files/meta?path=%2Ffolder1%2Ffile.png', headers);
expect(body).toEqual(response);
});

it.each(pathEncodingCases)(
'When the file path is %j then it should encode it as %s',
async (filePath, encodedPath) => {
// Arrange
const callStub = vi.spyOn(HttpClient.prototype, 'get').mockResolvedValue({});
const { client, headers } = clientAndHeaders({});

// Act
await client.getFileByPath(filePath);

// Assert
expect(callStub).toHaveBeenCalledWith(`files/meta?path=${encodedPath}`, headers);
},
);
});
});

describe('-> favorites', () => {
Expand Down
Loading