lz-api-client
Advanced tools
Comparing version 0.14.1 to 0.14.2
@@ -15,2 +15,3 @@ "use strict"; | ||
const lz_schema_1 = require("lz-schema"); | ||
const auth_1 = require("./helpers/auth"); | ||
(0, vitest_1.describe)('AccountService.verifyEmail', {}, () => { | ||
@@ -40,2 +41,66 @@ (0, vitest_1.test)('should return failure if not token', () => __awaiter(void 0, void 0, void 0, function* () { | ||
}); | ||
(0, vitest_1.describe)('AccountService.uploadProfileImage', {}, () => { | ||
(0, vitest_1.test)('should return failure if file is not image', () => __awaiter(void 0, void 0, void 0, function* () { | ||
try { | ||
const { bearerToken } = yield (0, auth_1.signIn)(); | ||
console.log('bearerToken', bearerToken); | ||
const client = (0, mocks_1.getClientWithMockedBearerToken)(bearerToken); | ||
const file = new File([''], 'filename'); | ||
yield client.account.uploadProfileImage(file); | ||
throw new Error('This test should have failed'); | ||
} | ||
catch (error) { | ||
(0, vitest_1.expect)(error).toHaveProperty('status', lz_schema_1.ResponseStatus.Fail); | ||
(0, vitest_1.expect)(error).toHaveProperty('message', 'Validation error'); | ||
(0, vitest_1.expect)(error).toHaveProperty('data', { | ||
file: 'Invalid file type. Allowed types are: jpeg, png, webp, avif, gif, svg, tiff', | ||
}); | ||
} | ||
})); | ||
(0, vitest_1.test)('should return failure if file is too large', () => __awaiter(void 0, void 0, void 0, function* () { | ||
try { | ||
const { bearerToken } = yield (0, auth_1.signIn)(); | ||
const client = (0, mocks_1.getClientWithMockedBearerToken)(bearerToken); | ||
const file = new File(['a'.repeat(6 * 1024 * 1024)], 'filename.jpg', { type: 'image/jpeg' }); | ||
yield client.account.uploadProfileImage(file); | ||
throw new Error('This test should have failed'); | ||
} | ||
catch (error) { | ||
(0, vitest_1.expect)(error).toHaveProperty('status', lz_schema_1.ResponseStatus.Fail); | ||
(0, vitest_1.expect)(error).toHaveProperty('message', 'Validation error'); | ||
(0, vitest_1.expect)(error).toHaveProperty('data', { | ||
file: 'File size too large. Maximum size is 5MB', | ||
}); | ||
} | ||
})); | ||
(0, vitest_1.test)('should return failure if no file is provided', () => __awaiter(void 0, void 0, void 0, function* () { | ||
try { | ||
const { bearerToken } = yield (0, auth_1.signIn)(); | ||
const client = (0, mocks_1.getClientWithMockedBearerToken)(bearerToken); | ||
// biome-ignore lint/suspicious/noExplicitAny: To test validation error | ||
yield client.account.uploadProfileImage(undefined); | ||
throw new Error('This test should have failed'); | ||
} | ||
catch (error) { | ||
(0, vitest_1.expect)(error).toHaveProperty('status', lz_schema_1.ResponseStatus.Fail); | ||
(0, vitest_1.expect)(error).toHaveProperty('message', 'Validation error'); | ||
(0, vitest_1.expect)(error).toHaveProperty('data', { | ||
file: 'No file uploaded', | ||
}); | ||
} | ||
})); | ||
(0, vitest_1.test)('should return failure if image upload fails', () => __awaiter(void 0, void 0, void 0, function* () { | ||
try { | ||
const { bearerToken } = yield (0, auth_1.signIn)(); | ||
const client = (0, mocks_1.getClientWithMockedBearerToken)(bearerToken); | ||
const file = new File([''], 'filename.jpg', { type: 'image/jpeg' }); | ||
yield client.account.uploadProfileImage(file); | ||
throw new Error('This test should have failed'); | ||
} | ||
catch (error) { | ||
(0, vitest_1.expect)(error).toHaveProperty('status', lz_schema_1.ResponseStatus.Error); | ||
(0, vitest_1.expect)(error).toHaveProperty('message', 'Failed to compress image'); | ||
} | ||
})); | ||
}); | ||
//# sourceMappingURL=account-service.test.js.map |
@@ -89,3 +89,6 @@ "use strict"; | ||
const url = new URL(path, this.apiURL); | ||
const requestHeaders = this.buildRequestHeaders(Object.assign(Object.assign({}, headers), { 'Content-Type': 'multipart/form-data' })); | ||
const requestHeaders = this.buildRequestHeaders(headers); | ||
// Remove the content type header to allow the browser to set it automatically | ||
// when sending a file. This way it will also add automatically the form boundary | ||
requestHeaders.delete('Content-Type'); | ||
const formData = new FormData(); | ||
@@ -92,0 +95,0 @@ formData.append('file', file); |
{ | ||
"name": "lz-api-client", | ||
"version": "0.14.1", | ||
"version": "0.14.2", | ||
"description": "client sdk for layerZ api", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
88677
1656