Skip to content

Commit

Permalink
Merge pull request #379 from nfdi4plants/fixes
Browse files Browse the repository at this point in the history
Update templates json parsing
  • Loading branch information
HLWeil authored Jun 12, 2024
2 parents 2951259 + aa28494 commit 2541449
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 3 deletions.
3 changes: 2 additions & 1 deletion src/ARCtrl/Template.Web.fs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ open Fable.Core


let getTemplates(url: string option) =
let defaultURL = @"https://github.com/nfdi4plants/Swate-templates/releases/download/latest/templates.json"
let defaultURL = @"https://github.com/nfdi4plants/Swate-templates/releases/download/latest/templates_v2.0.0.json"

let url = defaultArg url defaultURL
async {
let! jsonString = ARCtrl.WebRequest.downloadFile url
Expand Down
2 changes: 1 addition & 1 deletion src/Json/Table/Templates.fs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ module Templates =
|> Encode.array

let decoder =
Decode.dict Template.decoder
Decode.array Template.decoder

let fromJsonString (jsonString: string) =
try Decode.fromJsonString decoder jsonString with
Expand Down
2 changes: 1 addition & 1 deletion tests/ARCtrl/Template.Tests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ open TestingUtils
let private tests_Web = testList "Web" [
testCaseAsync "getTemplates" <| async {
let! templatesMap = ARCtrl.Template.Web.getTemplates(None)
Expect.isTrue (templatesMap.Count > 0) "Count > 0"
Expect.isTrue (templatesMap.Length > 0) "Count > 0"
}
]

Expand Down
28 changes: 28 additions & 0 deletions tests/Json/Template.Tests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,36 @@ let tests_Template =
Expect.equal actual expected "template"
]

let tests_Templates =
testList "templates" [
testCase "roundabout" <| fun _ ->
let table1 = ArcTable.init("My Table")
table1.AddColumn(CompositeHeader.Input IOType.Source, [|for i in 0 .. 9 do yield CompositeCell.createFreeText($"Source1 {i}")|])
table1.AddColumn(CompositeHeader.Output IOType.Data, [|for i in 0 .. 9 do yield CompositeCell.createFreeText($"Output1 {i}")|])
let template1 = Template.init("MyTemplate")
template1.Table <- table1
template1.Authors <- ResizeArray [|ARCtrl.Person.create(firstName="John", lastName="Doe"); ARCtrl.Person.create(firstName="Jane", lastName="Doe");|]
template1.EndpointRepositories <- ResizeArray [|ARCtrl.OntologyAnnotation("Test"); ARCtrl.OntologyAnnotation("Testing second")|]

let table2 = ArcTable.init("My Table 2")
table2.AddColumn(CompositeHeader.Input IOType.Source, [|for i in 0 .. 9 do yield CompositeCell.createFreeText($"Source2 {i}")|])
table2.AddColumn(CompositeHeader.Output IOType.Data, [|for i in 0 .. 9 do yield CompositeCell.createFreeText($"Output2 {i}")|])
let template2 = Template.init("MyTemplate 2")
template2.Table <- table2
template2.Authors <- ResizeArray [|ARCtrl.Person.create(firstName="John", lastName="Millter"); ARCtrl.Person.create(firstName="Jane", lastName="Miller");|]
template2.EndpointRepositories <- ResizeArray [|ARCtrl.OntologyAnnotation("Test2"); ARCtrl.OntologyAnnotation("Testing second2")|]

let templates = [|template1; template2|]

let json = Templates.toJsonString(4) templates
let actual = Templates.fromJsonString json

Expect.equal actual.Length templates.Length "Count"
Expect.equal actual.[0].Id templates.[0].Id "id"
]

let main = testList "Template" [
tests_Organisation
tests_Template
tests_Templates
]

0 comments on commit 2541449

Please sign in to comment.