Skip to content

Commit

Permalink
feat(FilesCountInfoIntegration): rename some methods
Browse files Browse the repository at this point in the history
  • Loading branch information
MellyGray committed Sep 6, 2023
1 parent 00ef077 commit 3265f55
Show file tree
Hide file tree
Showing 24 changed files with 75 additions and 75 deletions.
4 changes: 2 additions & 2 deletions src/files/domain/repositories/FileRepository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ export interface FileRepository {
paginationInfo?: FilePaginationInfo,
criteria?: FileCriteria
) => Promise<File[]>
getCountInfoByDatasetPersistentId: (
getFilesCountInfoByDatasetPersistentId: (
datasetPersistentId: string,
datasetVersion: DatasetVersion
) => Promise<FilesCountInfo>
getFileUserPermissionsById: (id: number) => Promise<FileUserPermissions>
getUserPermissionsById: (id: number) => Promise<FileUserPermissions>
}
4 changes: 2 additions & 2 deletions src/files/domain/useCases/checkFileDownloadPermission.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export async function checkFileDownloadPermission(
file: File
): Promise<boolean> {
if (file.version.publishingStatus === FilePublishingStatus.DEACCESSIONED) {
return fileRepository.getFileUserPermissionsById(file.id).then((permissions) => {
return fileRepository.getUserPermissionsById(file.id).then((permissions) => {
return permissions.canEditDataset
})
}
Expand All @@ -16,7 +16,7 @@ export async function checkFileDownloadPermission(
return true
}

return fileRepository.getFileUserPermissionsById(file.id).then((permissions) => {
return fileRepository.getUserPermissionsById(file.id).then((permissions) => {
return permissions.canDownloadFile
})
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export async function checkFileEditDatasetPermission(
fileRepository: FileRepository,
file: File
): Promise<boolean> {
return fileRepository.getFileUserPermissionsById(file.id).then((permissions) => {
return fileRepository.getUserPermissionsById(file.id).then((permissions) => {
return permissions.canEditDataset
})
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export async function getFilesCountInfoByDatasetPersistentId(
datasetVersion: DatasetVersion
): Promise<FilesCountInfo> {
return fileRepository
.getCountInfoByDatasetPersistentId(datasetPersistentId, datasetVersion)
.getFilesCountInfoByDatasetPersistentId(datasetPersistentId, datasetVersion)
.catch((error: Error) => {
throw new Error(error.message)
})
Expand Down
4 changes: 2 additions & 2 deletions src/files/infrastructure/FileJSDataverseRepository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ export class FileJSDataverseRepository implements FileRepository {
return Promise.resolve(0)
}

getCountInfoByDatasetPersistentId(
getFilesCountInfoByDatasetPersistentId(
// eslint-disable-next-line unused-imports/no-unused-vars
datasetPersistentId: string,
// eslint-disable-next-line unused-imports/no-unused-vars
Expand All @@ -77,7 +77,7 @@ export class FileJSDataverseRepository implements FileRepository {
})
}

getFileUserPermissionsById(id: number): Promise<FileUserPermissions> {
getUserPermissionsById(id: number): Promise<FileUserPermissions> {
return getFileUserPermissions
.execute(id)
.then((jsFileUserPermissions) =>
Expand Down
4 changes: 2 additions & 2 deletions src/stories/files/FileMockLoadingRepository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export class FileMockLoadingRepository implements FileRepository {
})
}

getCountInfoByDatasetPersistentId(
getFilesCountInfoByDatasetPersistentId(
// eslint-disable-next-line unused-imports/no-unused-vars
datasetPersistentId: string,
// eslint-disable-next-line unused-imports/no-unused-vars
Expand All @@ -32,7 +32,7 @@ export class FileMockLoadingRepository implements FileRepository {
})
}
// eslint-disable-next-line unused-imports/no-unused-vars
getFileUserPermissionsById(id: number): Promise<FileUserPermissions> {
getUserPermissionsById(id: number): Promise<FileUserPermissions> {
return new Promise((resolve) => {
setTimeout(() => {
resolve(FileUserPermissionsMother.create())
Expand Down
4 changes: 2 additions & 2 deletions src/stories/files/FileMockNoDataRepository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export class FileMockNoDataRepository implements FileRepository {
})
}

getCountInfoByDatasetPersistentId(
getFilesCountInfoByDatasetPersistentId(
// eslint-disable-next-line unused-imports/no-unused-vars
datasetPersistentId: string,
// eslint-disable-next-line unused-imports/no-unused-vars
Expand All @@ -33,7 +33,7 @@ export class FileMockNoDataRepository implements FileRepository {
})
}
// eslint-disable-next-line unused-imports/no-unused-vars
getFileUserPermissionsById(id: number): Promise<FileUserPermissions> {
getUserPermissionsById(id: number): Promise<FileUserPermissions> {
return new Promise((resolve) => {
setTimeout(() => {
resolve(FileUserPermissionsMother.create())
Expand Down
4 changes: 2 additions & 2 deletions src/stories/files/FileMockNoFiltersRepository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export class FileMockNoFiltersRepository implements FileRepository {
})
}

getCountInfoByDatasetPersistentId(
getFilesCountInfoByDatasetPersistentId(
// eslint-disable-next-line unused-imports/no-unused-vars
datasetPersistentId: string,
// eslint-disable-next-line unused-imports/no-unused-vars
Expand All @@ -34,7 +34,7 @@ export class FileMockNoFiltersRepository implements FileRepository {
})
}
// eslint-disable-next-line unused-imports/no-unused-vars
getFileUserPermissionsById(id: number): Promise<FileUserPermissions> {
getUserPermissionsById(id: number): Promise<FileUserPermissions> {
return new Promise((resolve) => {
setTimeout(() => {
resolve(FileUserPermissionsMother.create())
Expand Down
4 changes: 2 additions & 2 deletions src/stories/files/FileMockRepository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export class FileMockRepository implements FileRepository {
})
}

getCountInfoByDatasetPersistentId(
getFilesCountInfoByDatasetPersistentId(
// eslint-disable-next-line unused-imports/no-unused-vars
datasetPersistentId: string,
// eslint-disable-next-line unused-imports/no-unused-vars
Expand All @@ -35,7 +35,7 @@ export class FileMockRepository implements FileRepository {
})
}
// eslint-disable-next-line unused-imports/no-unused-vars
getFileUserPermissionsById(id: number): Promise<FileUserPermissions> {
getUserPermissionsById(id: number): Promise<FileUserPermissions> {
return new Promise((resolve) => {
setTimeout(() => {
resolve(FileUserPermissionsMother.create())
Expand Down
2 changes: 1 addition & 1 deletion src/stories/files/FileWithDeniedPermissionsRepository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export class FileWithDeniedPermissionsRepository
implements FileRepository
{
// eslint-disable-next-line unused-imports/no-unused-vars
getFileUserPermissionsById(id: number): Promise<FileUserPermissions> {
getUserPermissionsById(id: number): Promise<FileUserPermissions> {
return new Promise((resolve) => {
setTimeout(() => {
resolve(FileUserPermissionsMother.createWithDeniedPermissions())
Expand Down
2 changes: 1 addition & 1 deletion src/stories/files/FileWithGrantedPermissionsRepository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export class FileWithGrantedPermissionsRepository
implements FileRepository
{
// eslint-disable-next-line unused-imports/no-unused-vars
getFileUserPermissionsById(id: number): Promise<FileUserPermissions> {
getUserPermissionsById(id: number): Promise<FileUserPermissions> {
return new Promise((resolve) => {
setTimeout(() => {
resolve(FileUserPermissionsMother.createWithGrantedPermissions())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ const filePaginationInfo = new FilePaginationInfo(1, 10, 200)
describe('DatasetFiles', () => {
beforeEach(() => {
fileRepository.getAllByDatasetPersistentId = cy.stub().resolves(testFiles)
fileRepository.getCountInfoByDatasetPersistentId = cy.stub().resolves(testFilesCountInfo)
fileRepository.getFilesCountInfoByDatasetPersistentId = cy.stub().resolves(testFilesCountInfo)
})

it('renders the files table', () => {
Expand Down Expand Up @@ -180,7 +180,7 @@ describe('DatasetFiles', () => {
datasetVersion
)

cy.wrap(fileRepository.getCountInfoByDatasetPersistentId).should(
cy.wrap(fileRepository.getFilesCountInfoByDatasetPersistentId).should(
'be.calledWith',
datasetPersistentId,
datasetVersion
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ describe('FileActionsHeader', () => {
userRepository.removeAuthenticated = cy.stub().resolves()
const files = FileMother.createMany(2)
const fileRepository: FileRepository = {} as FileRepository
fileRepository.getFileUserPermissionsById = cy.stub().resolves(
fileRepository.getUserPermissionsById = cy.stub().resolves(
FileUserPermissionsMother.create({
fileId: files[0].id,
canEditDataset: true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ describe('EditFilesMenu', () => {
beforeEach(() => {
userRepository.getAuthenticated = cy.stub().resolves(user)
userRepository.removeAuthenticated = cy.stub().resolves()
fileRepository.getFileUserPermissionsById = cy.stub().resolves(
fileRepository.getUserPermissionsById = cy.stub().resolves(
FileUserPermissionsMother.create({
fileId: files[0].id,
canEditDataset: true
Expand Down Expand Up @@ -74,7 +74,7 @@ describe('EditFilesMenu', () => {
})

it.skip('does not render the Edit Files menu when the user does not have update dataset permissions', () => {
fileRepository.getFileUserPermissionsById = cy.stub().resolves(
fileRepository.getUserPermissionsById = cy.stub().resolves(
FileUserPermissionsMother.create({
fileId: files[0].id,
canEditDataset: false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ describe('FileActionButtons', () => {
userRepository.getAuthenticated = cy.stub().resolves(user)
userRepository.removeAuthenticated = cy.stub().resolves()
const fileRepository: FileRepository = {} as FileRepository
fileRepository.getFileUserPermissionsById = cy.stub().resolves(
fileRepository.getUserPermissionsById = cy.stub().resolves(
FileUserPermissionsMother.create({
fileId: file.id,
canEditDataset: true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ describe('AccessStatus', () => {
it('renders the access status restricted with access', () => {
const fileRestrictedWithAccess = FileMother.createWithRestrictedAccessWithAccessGranted()
const fileRepository: FileRepository = {} as FileRepository
fileRepository.getFileUserPermissionsById = cy.stub().resolves(
fileRepository.getUserPermissionsById = cy.stub().resolves(
FileUserPermissionsMother.create({
fileId: fileRestrictedWithAccess.id,
canDownloadFile: true
Expand All @@ -47,7 +47,7 @@ describe('AccessStatus', () => {
it('renders the access status embargoed', () => {
const fileRestrictedWithAccess = FileMother.createWithRestrictedAccessWithAccessGranted()
const fileRepository: FileRepository = {} as FileRepository
fileRepository.getFileUserPermissionsById = cy.stub().resolves(
fileRepository.getUserPermissionsById = cy.stub().resolves(
FileUserPermissionsMother.create({
fileId: fileRestrictedWithAccess.id,
canDownloadFile: true
Expand Down Expand Up @@ -75,7 +75,7 @@ describe('AccessStatus', () => {
it('renders the access status embargoed restricted with access', () => {
const fileRestrictedWithAccess = FileMother.createWithRestrictedAccessWithAccessGranted()
const fileRepository: FileRepository = {} as FileRepository
fileRepository.getFileUserPermissionsById = cy.stub().resolves(
fileRepository.getUserPermissionsById = cy.stub().resolves(
FileUserPermissionsMother.create({
fileId: fileRestrictedWithAccess.id,
canDownloadFile: true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ describe('RequestAccessOption', () => {
it('does not render the request access button when the file status is public', () => {
const filePublic = FileMother.createWithPublicAccess()
const fileRepository: FileRepository = {} as FileRepository
fileRepository.getFileUserPermissionsById = cy.stub().resolves(
fileRepository.getUserPermissionsById = cy.stub().resolves(
FileUserPermissionsMother.create({
fileId: filePublic.id,
canDownloadFile: true
Expand All @@ -96,7 +96,7 @@ describe('RequestAccessOption', () => {
it('does not render the request access button when the file status is restricted with access granted', () => {
const fileRestrictedWithAccess = FileMother.createWithRestrictedAccessWithAccessGranted()
const fileRepository: FileRepository = {} as FileRepository
fileRepository.getFileUserPermissionsById = cy.stub().resolves(
fileRepository.getUserPermissionsById = cy.stub().resolves(
FileUserPermissionsMother.create({
fileId: fileRestrictedWithAccess.id,
canDownloadFile: true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ describe('FileOptionsMenu', () => {
beforeEach(() => {
userRepository.getAuthenticated = cy.stub().resolves(user)
userRepository.removeAuthenticated = cy.stub().resolves()
fileRepository.getFileUserPermissionsById = cy.stub().resolves(
fileRepository.getUserPermissionsById = cy.stub().resolves(
FileUserPermissionsMother.create({
fileId: file.id,
canEditDataset: true
Expand Down Expand Up @@ -71,7 +71,7 @@ describe('FileOptionsMenu', () => {
})

it('does not render is the user do not have permissions to update the dataset', () => {
fileRepository.getFileUserPermissionsById = cy.stub().resolves(
fileRepository.getUserPermissionsById = cy.stub().resolves(
FileUserPermissionsMother.create({
fileId: file.id,
canEditDataset: false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const fileRepository: FileRepository = {} as FileRepository
describe('FileThumbnail', () => {
it('renders FileThumbnailPreviewImage when thumbnail is provided and file can be downloaded', () => {
const file = FileMother.createWithThumbnail()
fileRepository.getFileUserPermissionsById = cy.stub().resolves(
fileRepository.getUserPermissionsById = cy.stub().resolves(
FileUserPermissionsMother.create({
fileId: file.id,
canDownloadFile: true
Expand Down Expand Up @@ -40,7 +40,7 @@ describe('FileThumbnail', () => {

it('renders FileThumbnailPreviewImage when thumbnail is provided with unlocked icon if restricted with access', () => {
const file = FileMother.createWithThumbnailRestrictedWithAccessGranted()
fileRepository.getFileUserPermissionsById = cy.stub().resolves(
fileRepository.getUserPermissionsById = cy.stub().resolves(
FileUserPermissionsMother.create({
fileId: file.id,
canDownloadFile: true
Expand Down Expand Up @@ -101,7 +101,7 @@ describe('FileThumbnail', () => {

it('renders FileThumbnailIcon when thumbnail is not provided with unlock icon when restricted with access', () => {
const file = FileMother.createWithRestrictedAccessWithAccessGranted()
fileRepository.getFileUserPermissionsById = cy.stub().resolves(
fileRepository.getUserPermissionsById = cy.stub().resolves(
FileUserPermissionsMother.create({
fileId: file.id,
canDownloadFile: true
Expand Down
12 changes: 6 additions & 6 deletions tests/component/sections/dataset/dataset-files/useFiles.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ const FilesTableTestComponent = ({ datasetPersistentId }: { datasetPersistentId:
describe('useFiles', () => {
beforeEach(() => {
fileRepository.getAllByDatasetPersistentId = cy.stub().resolves(files)
fileRepository.getCountInfoByDatasetPersistentId = cy.stub().resolves(filesCountInfo)
fileRepository.getFileUserPermissionsById = cy
fileRepository.getFilesCountInfoByDatasetPersistentId = cy.stub().resolves(filesCountInfo)
fileRepository.getUserPermissionsById = cy
.stub()
.resolves(FileUserPermissionsMother.create({ fileId: files[0].id }))
})
Expand Down Expand Up @@ -80,7 +80,7 @@ describe('useFiles', () => {
cy.customMount(<FilesTableTestComponent datasetPersistentId="persistentId" />)

cy.findByText('Loading...').should('exist')
cy.wrap(fileRepository.getCountInfoByDatasetPersistentId).should(
cy.wrap(fileRepository.getFilesCountInfoByDatasetPersistentId).should(
'be.calledOnceWith',
'persistentId'
)
Expand All @@ -98,7 +98,7 @@ describe('useFiles', () => {
it('calls the file repository to get the permissions before removing the loading', () => {
const files = FileMother.createMany(5)
fileRepository.getAllByDatasetPersistentId = cy.stub().resolves(files)
fileRepository.getFileUserPermissionsById = cy.stub().resolves(
fileRepository.getUserPermissionsById = cy.stub().resolves(
new Promise((resolve) => {
setTimeout(() => {
resolve(FileUserPermissionsMother.create({ fileId: files[0].id }))
Expand All @@ -116,14 +116,14 @@ describe('useFiles', () => {
cy.wrap(fileRepository.getAllByDatasetPersistentId).should('be.calledOnceWith', 'persistentId')

cy.findByText('Loading...').should('exist')
cy.wrap(fileRepository.getFileUserPermissionsById).should('be.calledWith', files[0].id)
cy.wrap(fileRepository.getUserPermissionsById).should('be.calledWith', files[0].id)

cy.findByText('Loading...').should('exist')
cy.findByText('Files count: 100').should('exist')
})

it('calls the file repository to get the files only if files count info is greater than 0', () => {
fileRepository.getCountInfoByDatasetPersistentId = cy
fileRepository.getFilesCountInfoByDatasetPersistentId = cy
.stub()
.resolves(FilesCountInfoMother.create({ total: 0 }))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,14 @@ function TestComponent({ file }: { file: File }) {
describe('useFileDownloadPermission', () => {
beforeEach(() => {
fileRepository.getAllByDatasetPersistentId = cy.stub().resolves([])
fileRepository.getCountInfoByDatasetPersistentId = cy
fileRepository.getFilesCountInfoByDatasetPersistentId = cy
.stub()
.resolves(FilesCountInfoMother.create())
})

it('should return file download permission', () => {
const file = FileMother.createDeaccessioned()
fileRepository.getFileUserPermissionsById = cy
fileRepository.getUserPermissionsById = cy
.stub()
.resolves(FileUserPermissionsMother.create({ fileId: file.id, canEditDataset: true }))

Expand All @@ -41,13 +41,13 @@ describe('useFileDownloadPermission', () => {
</FilePermissionsProvider>
)

cy.wrap(fileRepository.getFileUserPermissionsById).should('be.calledWith', file.id)
cy.wrap(fileRepository.getUserPermissionsById).should('be.calledWith', file.id)
cy.findByText('Has download permission').should('exist')
})

it('should return false for file download permission if there is an error', () => {
const file = FileMother.createDeaccessioned()
fileRepository.getFileUserPermissionsById = cy
fileRepository.getUserPermissionsById = cy
.stub()
.rejects(new Error('Error getting file user permissions'))

Expand All @@ -57,7 +57,7 @@ describe('useFileDownloadPermission', () => {
</FilePermissionsProvider>
)

cy.wrap(fileRepository.getFileUserPermissionsById).should('be.calledWith', file.id)
cy.wrap(fileRepository.getUserPermissionsById).should('be.calledWith', file.id)
cy.findByText('Does not have download permission').should('exist')
})
})
Loading

0 comments on commit 3265f55

Please sign in to comment.