Skip to content

Commit 4ae6bd0

Browse files
committed
fixes and tests for updateContracts when assays or studies are added
1 parent 19b6a4c commit 4ae6bd0

3 files changed

Lines changed: 85 additions & 3 deletions

File tree

src/Contract/ArcAssay.fs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ module AssayContractExtensions =
2626
let c = Contract.createCreate(path, DTOType.ISA_Assay, DTO.Spreadsheet (this |> ArcAssay.toFsWorkbook))
2727
[|
2828
if withFolder then
29-
let folderFS = FileSystemTree.createAssayFolder this.Identifier
29+
let folderFS = FileSystemTree.createAssaysFolder([|FileSystemTree.createAssayFolder this.Identifier|])
3030
for p in folderFS.ToFilePaths(false) do
3131
if p <> path then Contract.createCreate(p, DTOType.PlainText)
3232
c

src/FileSystem/FileSystemTree.fs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -225,13 +225,13 @@ type FileSystemTree =
225225
static member createAssaysFolder(assays : FileSystemTree array) =
226226
FileSystemTree.createFolder(
227227
ARCtrl.Path.AssaysFolderName,
228-
Array.append [|FileSystemTree.createGitKeepFile()|] assays
228+
Array.append [|if assays.Length = 0 then FileSystemTree.createGitKeepFile()|] assays
229229
)
230230

231231
static member createStudiesFolder(studies : FileSystemTree array) =
232232
FileSystemTree.createFolder(
233233
ARCtrl.Path.StudiesFolderName,
234-
Array.append [|FileSystemTree.createGitKeepFile()|] studies
234+
Array.append [|if studies.Length = 0 then FileSystemTree.createGitKeepFile()|] studies
235235
)
236236

237237
static member createWorkflowsFolder(workflows : FileSystemTree array) =

tests/ARCtrl/ARCtrl.Tests.fs

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,88 @@ let private tests_updateContracts = testList "update_contracts" [
335335
Expect.exists contracts (fun c -> c.Path = "isa.investigation.xlsx") "Contract for investigation folder missing"
336336
Expect.exists contracts (fun c -> c.Path = "isa.investigation.xlsx" && c.DTOType.IsSome && c.DTOType.Value = Contract.DTOType.ISA_Investigation) "Contract for investigation exisiting but has wrong DTO type"
337337
)
338+
testCase "empty_addAssay" (fun _ ->
339+
let i = ArcInvestigation("MyInvestigation")
340+
let arc = ARC(isa = i)
341+
arc.GetWriteContracts() |> ignore
342+
i.InitAssay("MyAssay") |> ignore
343+
// As the ARC is compeletely empty, GetUpdateContracts should return the same contracts as GetWriteContracts
344+
let contracts = arc.GetUpdateContracts()
345+
let contractPathsString = contracts |> Array.map (fun c -> c.Path) |> String.concat ", "
346+
Expect.equal contracts.Length 4 $"Should contain exactly as much contracts as needed for new assay: {contractPathsString}"
347+
// Assay file contract
348+
let assayFilePath = "assays/MyAssay/isa.assay.xlsx"
349+
let assayFileContract = Expect.wantSome (contracts |> Array.tryFind (fun c -> c.Path = assayFilePath)) $"Assay file contract for {assayFilePath} missing"
350+
Expect.equal assayFileContract.Operation Operation.CREATE "Operation for assay file contract should be CREATE"
351+
let assayFileDTOType = Expect.wantSome assayFileContract.DTOType "DTOType for assay file contract missing"
352+
Expect.equal assayFileDTOType DTOType.ISA_Assay "DTOType for assay file contract should be ISA_Assay"
353+
let assayFileDTO = Expect.wantSome assayFileContract.DTO "DTO for assay file contract missing"
354+
let wb = assayFileDTO.AsSpreadsheet() :?> FsWorkbook
355+
let assay = ArcAssay.fromFsWorkbook wb
356+
Expect.equal assay.Identifier "MyAssay" "Assay identifier should be set"
357+
// readme contract
358+
let readmeFilePath = "assays/MyAssay/README.md"
359+
let readmeContract = Expect.wantSome (contracts |> Array.tryFind (fun c -> c.Path = readmeFilePath)) $"Readme contract for {readmeFilePath} missing"
360+
Expect.equal readmeContract.Operation Operation.CREATE "Operation for readme contract should be CREATE"
361+
let readmeDTOType = Expect.wantSome readmeContract.DTOType "DTOType for readme contract missing"
362+
Expect.equal readmeDTOType DTOType.PlainText "DTOType for readme contract should be ISA_Readme"
363+
Expect.isNone readmeContract.DTO "DTO for readme contract should be None"
364+
// protocols gitkeep contract
365+
let protocolsGitkeepFilePath = "assays/MyAssay/protocols/.gitkeep"
366+
let protocolsGitkeepContract = Expect.wantSome (contracts |> Array.tryFind (fun c -> c.Path = protocolsGitkeepFilePath)) $"Protocols gitkeep contract for {protocolsGitkeepFilePath} missing"
367+
Expect.equal protocolsGitkeepContract.Operation Operation.CREATE "Operation for protocols gitkeep contract should be CREATE"
368+
let protocolsGitkeepDTOType = Expect.wantSome protocolsGitkeepContract.DTOType "DTOType for protocols gitkeep contract missing"
369+
Expect.equal protocolsGitkeepDTOType DTOType.PlainText "DTOType for protocols gitkeep contract should be GitKeep"
370+
Expect.isNone protocolsGitkeepContract.DTO "DTO for protocols gitkeep contract should be None"
371+
// dataset gitkeep contract
372+
let datasetGitkeepFilePath = "assays/MyAssay/dataset/.gitkeep"
373+
let datasetGitkeepContract = Expect.wantSome (contracts |> Array.tryFind (fun c -> c.Path = datasetGitkeepFilePath)) $"Dataset gitkeep contract for {datasetGitkeepFilePath} missing"
374+
Expect.equal datasetGitkeepContract.Operation Operation.CREATE "Operation for dataset gitkeep contract should be CREATE"
375+
let datasetGitkeepDTOType = Expect.wantSome datasetGitkeepContract.DTOType "DTOType for dataset gitkeep contract missing"
376+
Expect.equal datasetGitkeepDTOType DTOType.PlainText "DTOType for dataset gitkeep contract should be GitKeep"
377+
Expect.isNone datasetGitkeepContract.DTO "DTO for dataset gitkeep contract should be None"
378+
)
379+
testCase "empty_addStudy" (fun _ ->
380+
let i = ArcInvestigation("MyInvestigation")
381+
let arc = ARC(isa = i)
382+
arc.GetWriteContracts() |> ignore
383+
i.InitStudy("MyStudy") |> ignore
384+
// As the ARC is compeletely empty, GetUpdateContracts should return the same contracts as GetWriteContracts
385+
let contracts = arc.GetUpdateContracts()
386+
let contractPathsString = contracts |> Array.map (fun c -> c.Path) |> String.concat ", "
387+
Expect.equal contracts.Length 4 $"Should contain exactly as much contracts as needed for new study: {contractPathsString}"
388+
// Study file contract
389+
let studyFilePath = "studies/MyStudy/isa.study.xlsx"
390+
let studyFileContract = Expect.wantSome (contracts |> Array.tryFind (fun c -> c.Path = studyFilePath)) $"Study file contract for {studyFilePath} missing"
391+
Expect.equal studyFileContract.Operation Operation.CREATE "Operation for study file contract should be CREATE"
392+
let studyFileDTOType = Expect.wantSome studyFileContract.DTOType "DTOType for study file contract missing"
393+
Expect.equal studyFileDTOType DTOType.ISA_Study "DTOType for study file contract should be ISA_Study"
394+
let studyFileDTO = Expect.wantSome studyFileContract.DTO "DTO for study file contract missing"
395+
let wb = studyFileDTO.AsSpreadsheet() :?> FsWorkbook
396+
let study,_ = ArcStudy.fromFsWorkbook wb
397+
Expect.equal study.Identifier "MyStudy" "Study identifier should be set"
398+
// readme contract
399+
let readmeFilePath = "studies/MyStudy/README.md"
400+
let readmeContract = Expect.wantSome (contracts |> Array.tryFind (fun c -> c.Path = readmeFilePath)) $"Readme contract for {readmeFilePath} missing"
401+
Expect.equal readmeContract.Operation Operation.CREATE "Operation for readme contract should be CREATE"
402+
let readmeDTOType = Expect.wantSome readmeContract.DTOType "DTOType for readme contract missing"
403+
Expect.equal readmeDTOType DTOType.PlainText "DTOType for readme contract should be ISA_Readme"
404+
Expect.isNone readmeContract.DTO "DTO for readme contract should be None"
405+
// protocols gitkeep contract
406+
let protocolsGitkeepFilePath = "studies/MyStudy/protocols/.gitkeep"
407+
let protocolsGitkeepContract = Expect.wantSome (contracts |> Array.tryFind (fun c -> c.Path = protocolsGitkeepFilePath)) $"Protocols gitkeep contract for {protocolsGitkeepFilePath} missing"
408+
Expect.equal protocolsGitkeepContract.Operation Operation.CREATE "Operation for protocols gitkeep contract should be CREATE"
409+
let protocolsGitkeepDTOType = Expect.wantSome protocolsGitkeepContract.DTOType "DTOType for protocols gitkeep contract missing"
410+
Expect.equal protocolsGitkeepDTOType DTOType.PlainText "DTOType for protocols gitkeep contract should be GitKeep"
411+
Expect.isNone protocolsGitkeepContract.DTO "DTO for protocols gitkeep contract should be None"
412+
// resources gitkeep contract
413+
let resourcesGitkeepFilePath = "studies/MyStudy/resources/.gitkeep"
414+
let resourcesGitkeepContract = Expect.wantSome (contracts |> Array.tryFind (fun c -> c.Path = resourcesGitkeepFilePath)) $"Resources gitkeep contract for {resourcesGitkeepFilePath} missing"
415+
Expect.equal resourcesGitkeepContract.Operation Operation.CREATE "Operation for resources gitkeep contract should be CREATE"
416+
let resourcesGitkeepDTOType = Expect.wantSome resourcesGitkeepContract.DTOType "DTOType for resources gitkeep contract missing"
417+
Expect.equal resourcesGitkeepDTOType DTOType.PlainText "DTOType for resources gitkeep contract should be GitKeep"
418+
Expect.isNone resourcesGitkeepContract.DTO "DTO for resources gitkeep contract should be None"
419+
)
338420
testCase "init_simpleISA" (fun _ ->
339421
let inv = ArcInvestigation("MyInvestigation", "BestTitle")
340422
inv.InitStudy("MyStudy").InitRegisteredAssay("MyAssay") |> ignore

0 commit comments

Comments
 (0)