Update create.ts
This commit is contained in:
parent
e214ccb7bd
commit
c005716c5f
|
@ -27,6 +27,8 @@ describe('/drive/files/create', () => {
|
||||||
|
|
||||||
let root: MiUser;
|
let root: MiUser;
|
||||||
let role_tinyAttachment: MiRole;
|
let role_tinyAttachment: MiRole;
|
||||||
|
let role_imageOnly: MiRole;
|
||||||
|
let role_allowAllTypes: MiRole;
|
||||||
|
|
||||||
let folder: MiDriveFolder;
|
let folder: MiDriveFolder;
|
||||||
|
|
||||||
|
@ -66,10 +68,34 @@ describe('/drive/files/create', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
roleService = module.get<RoleService>(RoleService);
|
roleService = module.get<RoleService>(RoleService);
|
||||||
role_tinyAttachment = await roleService.create({
|
role_imageOnly = await roleService.create({
|
||||||
name: 'test-role001',
|
name: 'test-role001',
|
||||||
description: 'Test role001 description',
|
description: 'Test role001 description',
|
||||||
target: 'manual',
|
target: 'manual',
|
||||||
|
policies: {
|
||||||
|
uploadableFileTypes: {
|
||||||
|
useDefault: false,
|
||||||
|
priority: 1,
|
||||||
|
value: ['image/png'],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
|
role_allowAllTypes = await roleService.create({
|
||||||
|
name: 'test-role002',
|
||||||
|
description: 'Test role002 description',
|
||||||
|
target: 'manual',
|
||||||
|
policies: {
|
||||||
|
uploadableFileTypes: {
|
||||||
|
useDefault: false,
|
||||||
|
priority: 1,
|
||||||
|
value: ['*/*'],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
|
role_tinyAttachment = await roleService.create({
|
||||||
|
name: 'test-role003',
|
||||||
|
description: 'Test role003 description',
|
||||||
|
target: 'manual',
|
||||||
policies: {
|
policies: {
|
||||||
maxFileSizeMb: {
|
maxFileSizeMb: {
|
||||||
useDefault: false,
|
useDefault: false,
|
||||||
|
@ -77,11 +103,6 @@ describe('/drive/files/create', () => {
|
||||||
// 10byte
|
// 10byte
|
||||||
value: 10 / 1024 / 1024,
|
value: 10 / 1024 / 1024,
|
||||||
},
|
},
|
||||||
uploadableFileTypes: {
|
|
||||||
useDefault: false,
|
|
||||||
priority: 1,
|
|
||||||
value: ['*/*'],
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -89,6 +110,10 @@ describe('/drive/files/create', () => {
|
||||||
beforeEach(async () => {
|
beforeEach(async () => {
|
||||||
await roleService.unassign(root.id, role_tinyAttachment.id).catch(() => {
|
await roleService.unassign(root.id, role_tinyAttachment.id).catch(() => {
|
||||||
});
|
});
|
||||||
|
await roleService.unassign(root.id, role_imageOnly.id).catch(() => {
|
||||||
|
});
|
||||||
|
await roleService.unassign(root.id, role_allowAllTypes.id).catch(() => {
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
afterAll(async () => {
|
afterAll(async () => {
|
||||||
|
@ -117,7 +142,9 @@ describe('/drive/files/create', () => {
|
||||||
.field('i', root.token ?? '');
|
.field('i', root.token ?? '');
|
||||||
}
|
}
|
||||||
|
|
||||||
test('200 ok', async () => {
|
test('200 ok (all types allowed)', async () => {
|
||||||
|
await roleService.assign(root.id, role_allowAllTypes.id);
|
||||||
|
|
||||||
const name = randomString();
|
const name = randomString();
|
||||||
const comment = randomString();
|
const comment = randomString();
|
||||||
const result = await postFile({
|
const result = await postFile({
|
||||||
|
@ -134,7 +161,24 @@ describe('/drive/files/create', () => {
|
||||||
expect(result.body.folderId).toBe(folder.id);
|
expect(result.body.folderId).toBe(folder.id);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('200 ok(with role)', async () => {
|
test('400 when not allowed type', async () => {
|
||||||
|
await roleService.assign(root.id, role_imageOnly.id);
|
||||||
|
|
||||||
|
const name = randomString();
|
||||||
|
const comment = randomString();
|
||||||
|
const result = await postFile({
|
||||||
|
name: name,
|
||||||
|
comment: comment,
|
||||||
|
isSensitive: true,
|
||||||
|
force: true,
|
||||||
|
fileContent: Buffer.from('a'.repeat(10)),
|
||||||
|
});
|
||||||
|
expect(result.statusCode).toBe(400);
|
||||||
|
expect(result.body.error.code).toBe('UNALLOWED_FILE_TYPE');
|
||||||
|
});
|
||||||
|
|
||||||
|
test('200 ok (with size limited role)', async () => {
|
||||||
|
await roleService.assign(root.id, role_allowAllTypes.id);
|
||||||
await roleService.assign(root.id, role_tinyAttachment.id);
|
await roleService.assign(root.id, role_tinyAttachment.id);
|
||||||
|
|
||||||
const name = randomString();
|
const name = randomString();
|
||||||
|
@ -154,6 +198,7 @@ describe('/drive/files/create', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
test('413 too large', async () => {
|
test('413 too large', async () => {
|
||||||
|
await roleService.assign(root.id, role_allowAllTypes.id);
|
||||||
await roleService.assign(root.id, role_tinyAttachment.id);
|
await roleService.assign(root.id, role_tinyAttachment.id);
|
||||||
|
|
||||||
const name = randomString();
|
const name = randomString();
|
||||||
|
|
Loading…
Reference in New Issue