This repository has been archived by the owner on Feb 27, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
[iOS] Add a local schema to building of “answers.json” #231
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
91 changes: 91 additions & 0 deletions
91
...ackage/Tests/BridgeClientExtensionTests/FileUpload/V2/AssessmentArchiveBuilderTests.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
// Created 9/13/23 | ||
// swift-tools-version:5.0 | ||
|
||
import XCTest | ||
@testable import BridgeClientExtension | ||
import JsonModel | ||
import ResultModel | ||
|
||
final class AssessmentArchiveBuilderTests: XCTestCase { | ||
|
||
override func setUpWithError() throws { | ||
// Put setup code here. This method is called before the invocation of each test method in the class. | ||
} | ||
|
||
override func tearDownWithError() throws { | ||
// Put teardown code here. This method is called after the invocation of each test method in the class. | ||
} | ||
|
||
func testSurveyAnswerBuilder() async throws { | ||
|
||
let assessmentResult = AssessmentResultObject(identifier: "example_survey") | ||
let answerResult1 = AnswerResultObject(identifier: "step1", value: .boolean(true), questionText: "Do you like pizza?") | ||
let answerResult2 = AnswerResultObject(identifier: "step2", value: .integer(42), questionText: "What is the answer to the universe and everything?") | ||
let answerResult3 = AnswerResultObject(identifier: "step3", value: .number(52.25), questionText: "How old are you?") | ||
let answerResult4 = AnswerResultObject(identifier: "step4", value: .string("brown fox"), questionText: "Who jumped over the lazy dog?") | ||
let answerResult5 = AnswerResultObject(identifier: "step5", value: .array([1,11]), questionText: "What are your favorite numbers?") | ||
assessmentResult.stepHistory = [answerResult1, answerResult2, answerResult3, answerResult4, answerResult5] | ||
|
||
guard let builder = AssessmentArchiveBuilder(assessmentResult) else { | ||
XCTFail("Unexpected NULL when creating the archiver") | ||
return | ||
} | ||
builder.archive.isTest = true | ||
let _ = try await builder.buildArchive() | ||
|
||
// Check each answer type | ||
XCTAssertEqual(builder.answers["step1"] as? Bool, true) | ||
XCTAssertEqual(builder.answers["step2"] as? Int, 42) | ||
XCTAssertEqual(builder.answers["step3"] as? Double, 52.25) | ||
XCTAssertEqual(builder.answers["step4"] as? String, "brown fox") | ||
XCTAssertEqual(builder.answers["step5"] as? String, "1,11") | ||
|
||
// Check that the answers match the expected values | ||
let expectedAnswers = try JSONSerialization.jsonObject(with: """ | ||
{ | ||
"step1" : true, | ||
"step2" : 42, | ||
"step3" : 52.25, | ||
"step4" : "brown fox", | ||
"step5" : "1,11" | ||
} | ||
""".data(using: .utf8)!) as! NSDictionary | ||
let answers = try builder.archive.addedFiles["answers.json"].map { try JSONSerialization.jsonObject(with: $0) } as? NSDictionary | ||
XCTAssertEqual(expectedAnswers, answers) | ||
|
||
// Check that the schema matches | ||
let expectedSchema = try JSONSerialization.jsonObject(with: """ | ||
{ | ||
"$id" : "answers_schema.json", | ||
"$schema" : "http://json-schema.org/draft-07/schema#", | ||
"type" : "object", | ||
"title" : "answers_schema", | ||
"description" : "example_survey", | ||
"properties" : { | ||
"step1" : { | ||
"type" : "boolean", | ||
"description" : "Do you like pizza?" | ||
}, | ||
"step2" : { | ||
"type" : "integer", | ||
"description" : "What is the answer to the universe and everything?" | ||
}, | ||
"step3" : { | ||
"type" : "number", | ||
"description" : "How old are you?" | ||
}, | ||
"step4" : { | ||
"type" : "string", | ||
"description" : "Who jumped over the lazy dog?" | ||
}, | ||
"step5" : { | ||
"type" : "string", | ||
"description" : "What are your favorite numbers?" | ||
}, | ||
} | ||
} | ||
""".data(using: .utf8)!) as! NSDictionary | ||
let schema = try builder.archive.addedFiles["answers_schema.json"].map { try JSONSerialization.jsonObject(with: $0) } as? NSDictionary | ||
XCTAssertEqual(expectedSchema, schema) | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems problematic to return nil for types not supported by the flatAnswer() function. Previously if we had a value it would get serialized into the answers file.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added "object" (though we don't actually have any currently supported question types that use this answer type).