salix/back/methods/image/specs/upload.spec.js

127 lines
3.8 KiB
JavaScript
Raw Normal View History

2023-01-24 08:04:43 +00:00
const {models} = require('vn-loopback/server/server');
2020-12-11 14:04:55 +00:00
describe('image upload()', () => {
describe('as buyer', () => {
const buyerId = 35;
const workerId = 1106;
2020-12-11 14:04:55 +00:00
const itemId = 4;
it('should try to upload a file for the collection "catalog" and throw a privileges error', async() => {
const ctx = {req: {accessToken: {userId: buyerId}},
args: {
id: workerId,
collection: 'user'
}
};
let error;
try {
2023-01-24 08:04:43 +00:00
await models.Image.upload(ctx);
2020-12-11 14:04:55 +00:00
} catch (err) {
error = err;
}
expect(error.message).toEqual(`You don't have enough privileges`);
});
2020-12-18 16:23:04 +00:00
it('should call to the TempContainer upload method for the collection "catalog"', async() => {
2023-01-24 08:04:43 +00:00
const containerModel = models.TempContainer;
2020-12-11 14:04:55 +00:00
spyOn(containerModel, 'upload');
const ctx = {req: {accessToken: {userId: buyerId}},
args: {
id: itemId,
collection: 'catalog'
}
};
try {
2023-01-24 08:04:43 +00:00
await models.Image.upload(ctx);
2020-12-11 14:04:55 +00:00
} catch (err) { }
expect(containerModel.upload).toHaveBeenCalled();
});
});
describe('as marketing', () => {
const marketingId = 51;
const workerId = 1106;
2020-12-11 14:04:55 +00:00
const itemId = 4;
2020-12-18 16:23:04 +00:00
it('should be able to call to the TempContainer upload method for the collection "user"', async() => {
2023-01-24 08:04:43 +00:00
const containerModel = models.TempContainer;
2020-12-11 14:04:55 +00:00
spyOn(containerModel, 'upload');
const ctx = {req: {accessToken: {userId: marketingId}},
args: {
id: workerId,
collection: 'user'
}
};
try {
2023-01-24 08:04:43 +00:00
await models.Image.upload(ctx);
2020-12-11 14:04:55 +00:00
} catch (err) { }
expect(containerModel.upload).toHaveBeenCalled();
});
2020-12-18 16:23:04 +00:00
it('should be able to call to the TempContainer upload method for the collection "catalog"', async() => {
2023-01-24 08:04:43 +00:00
const containerModel = models.TempContainer;
2020-12-11 14:04:55 +00:00
spyOn(containerModel, 'upload');
const ctx = {req: {accessToken: {userId: marketingId}},
args: {
id: itemId,
collection: 'catalog'
}
};
try {
2023-01-24 08:04:43 +00:00
await models.Image.upload(ctx);
2020-12-11 14:04:55 +00:00
} catch (err) { }
expect(containerModel.upload).toHaveBeenCalled();
});
});
describe('as hhrr', () => {
const hhrrId = 37;
const workerId = 1106;
2020-12-11 14:04:55 +00:00
const itemId = 4;
2020-12-18 16:23:04 +00:00
it('should upload a file for the collection "user" and call to the TempContainer upload method', async() => {
2023-01-24 08:04:43 +00:00
const containerModel = models.TempContainer;
2020-12-11 14:04:55 +00:00
spyOn(containerModel, 'upload');
const ctx = {req: {accessToken: {userId: hhrrId}},
2024-01-25 13:58:48 +00:00
args: {id: itemId, collection: 'user'}
2020-12-11 14:04:55 +00:00
};
try {
2023-01-24 08:04:43 +00:00
await models.Image.upload(ctx);
2020-12-11 14:04:55 +00:00
} catch (err) { }
expect(containerModel.upload).toHaveBeenCalled();
});
it('should try to upload a file for the collection "catalog" and throw a privilege error', async() => {
2024-01-25 13:58:48 +00:00
const ctx = {req: {accessToken: {userId: 1}},
2020-12-11 14:04:55 +00:00
args: {
id: workerId,
collection: 'catalog'
}
};
let error;
try {
2023-01-24 08:04:43 +00:00
await models.Image.upload(ctx);
2020-12-11 14:04:55 +00:00
} catch (err) {
error = err;
}
expect(error.message).toEqual(`You don't have enough privileges`);
});
});
});