Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update templates json parsing #379

Merged
merged 1 commit into from
Jun 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
]
Loading