[ACA-4618] Decouple ACA and Governance (#2757)

* [ACA-4618] Remove governance dependecies from ACA

* [ACA-4618] Move canOpenWithOffice evaluator to ACA shared

* [ACA-4618] Add missing unit test changes

* [ACA-4618] Prettier fixes
This commit is contained in:
MichalKinas
2022-11-04 12:15:33 +01:00
committed by GitHub
parent ae57a094b1
commit 8081bc81d6
8 changed files with 284 additions and 444 deletions

View File

@@ -551,4 +551,229 @@ describe('app.evaluators', () => {
expect(app.isContentServiceEnabled()).toBe(true);
});
});
describe('canOpenWithOffice', () => {
it('should return [false] if using SSO', () => {
const context: any = {
auth: {
isOauth: () => true
}
};
expect(app.canOpenWithOffice(context)).toBeFalsy();
});
it('should return [false] if no selection present', () => {
const context: any = {
selection: null
};
expect(app.canOpenWithOffice(context)).toBeFalsy();
});
it('should return [false] if no file selected', () => {
const context: any = {
selection: {
file: null
}
};
expect(app.canOpenWithOffice(context)).toBeFalsy();
});
it('should return [false] if selected file has no entry', () => {
const context: any = {
selection: {
file: {
entry: null
}
}
};
expect(app.canOpenWithOffice(context)).toBeFalsy();
});
it('should return [false] if selected file has no properties', () => {
const context: any = {
selection: {
file: {
entry: {
properties: null
}
}
}
};
expect(app.canOpenWithOffice(context)).toBeFalsy();
});
it('should return [false] if selected file is locked', () => {
const context: any = {
selection: {
file: {
entry: {
isLocked: true,
properties: {}
}
}
}
};
expect(app.canOpenWithOffice(context)).toBeFalsy();
});
it('should return [false] if selected file has no extension', () => {
const context: any = {
selection: {
file: {
entry: {
name: 'readme',
isLocked: false,
properties: {}
}
}
}
};
expect(app.canOpenWithOffice(context)).toBeFalsy();
});
it('should return [false] if extension is not supported', () => {
const context: any = {
selection: {
file: {
entry: {
name: 'run.exe',
isLocked: false,
properties: {}
}
}
}
};
expect(app.canOpenWithOffice(context)).toBeFalsy();
});
it('should return [false] if selected file has write lock', () => {
const context: any = {
selection: {
file: {
entry: {
name: 'document.docx',
isLocked: false,
properties: {
'cm:lockType': 'WRITE_LOCK'
}
}
}
}
};
expect(app.canOpenWithOffice(context)).toBeFalsy();
});
it('should return [false] if selected file has read-only lock', () => {
const context: any = {
selection: {
file: {
entry: {
name: 'document.docx',
isLocked: false,
properties: {
'cm:lockType': 'READ_ONLY_LOCK'
}
}
}
}
};
expect(app.canOpenWithOffice(context)).toBeFalsy();
});
it('should return [false] if current user is not lock owner', () => {
const context: any = {
profile: {
id: 'user1'
},
selection: {
file: {
entry: {
name: 'document.docx',
isLocked: false,
properties: {
'cm:lockType': 'READ_ONLY_LOCK',
'cm:lockOwner': {
id: 'user2'
}
}
}
}
}
};
expect(app.canOpenWithOffice(context)).toBeFalsy();
});
it('should return [false] if current user is lock owner', () => {
const context: any = {
profile: {
id: 'user1'
},
selection: {
file: {
entry: {
name: 'document.docx',
isLocked: false,
properties: {
'cm:lockType': 'READ_ONLY_LOCK',
'cm:lockOwner': {
id: 'user1'
}
}
}
}
}
};
expect(app.canOpenWithOffice(context)).toBeFalsy();
});
it('should return [false] if permissions check is false', () => {
const context: any = {
selection: {
file: {
entry: {
name: 'document.docx',
isLocked: false,
properties: {}
}
}
},
permissions: {
check: () => false
}
};
expect(app.canOpenWithOffice(context)).toBeFalsy();
});
it('should return [true] if all checks succeed', () => {
const context: any = {
selection: {
file: {
entry: {
name: 'document.docx',
isLocked: false,
properties: {}
}
}
},
permissions: {
check: () => true
}
};
expect(app.canOpenWithOffice(context)).toBeTruthy();
});
});
});