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

4604 test for get progress percentage checking #20

Merged
merged 3 commits into from
Dec 23, 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
25 changes: 23 additions & 2 deletions API-tests/database/portal_test_db.sql
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,9 @@ INSERT INTO `categories` (`categoryID`, `parentID`, `categoryName`, `categoryDes
('form_ce46b', '', 'Simple form', '', 1, 0, 1, NULL, 1, 0, '', NULL, 1697476029),
('form_f8b95', '', 'Multiple person designated', '', 4, 0, 1, NULL, 1, 0, '', NULL, 1698274593),
('leaf_devconsole', '', 'LEAF Developer Console', '', -2, 0, 0, NULL, 1, 0, '', NULL, 0),
('leaf_secure', '', 'Leaf Secure Certification', '', -1, 0, 0, NULL, 1, 0, '', NULL, 0);
('leaf_secure', '', 'Leaf Secure Certification', '', -1, 0, 0, NULL, 1, 0, '', NULL, 0),
('form_7664a', '', 'IFTHEN display status progress checking', '', 1, 0, 0, NULL, 1, 0, '', NULL, 1733265434),
('form_dac2a', '', 'Test IFTHEN staple', '', 0, 10, 0, NULL, 1, 0, '', NULL, 1733840407);

DROP TABLE IF EXISTS `category_count`;
CREATE TABLE `category_count` (
Expand Down Expand Up @@ -1121,6 +1123,8 @@ CREATE TABLE `category_staples` (
CONSTRAINT `category_staples_ibfk_1` FOREIGN KEY (`categoryID`) REFERENCES `categories` (`categoryID`) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3;

INSERT INTO `category_staples` (`categoryID`, `stapledCategoryID`) VALUES
('form_7664a', 'form_dac2a');

DROP TABLE IF EXISTS `data`;
CREATE TABLE `data` (
Expand Down Expand Up @@ -6219,7 +6223,24 @@ INSERT INTO `indicators` (`indicatorID`, `name`, `format`, `description`, `defau
(12, 'Single line text', 'text', '', '', NULL, 'form_2d609', NULL, NULL, NULL, NULL, 0, 0, '2023-10-17 14:48:05', 0, 0),
(13, 'Single line text', 'text', '', '', NULL, 'form_a9b9f', NULL, NULL, NULL, NULL, 0, 0, '2023-10-17 14:59:56', 0, 0),
(14, 'Reviewer 1', 'orgchart_employee', '', '', NULL, 'form_f8b95', NULL, NULL, NULL, NULL, 1, 0, '2023-10-25 22:56:24', 0, 0),
(15, 'Reviewer 2', 'orgchart_employee', '', '', 14, 'form_f8b95', NULL, NULL, NULL, NULL, 1, 0, '2023-10-25 22:56:33', 0, 0);
(15, 'Reviewer 2', 'orgchart_employee', '', '', 14, 'form_f8b95', NULL, NULL, NULL, NULL, 1, 0, '2023-10-25 22:56:33', 0, 0),
(16, 'Section 1', '', '', '', NULL, 'form_7664a', NULL, NULL, NULL, NULL, 0, -128, '2024-12-09 13:38:21', 0, 0),
(17, 'dropdown parent', 'dropdown\r\n\r\n1\r\n2\r\n3', '', '', 16, 'form_7664a', NULL, NULL, NULL, NULL, 1, -128, '2024-12-09 13:38:21', 0, 0),
(18, 'radio child (show if parent 2)', 'radio\r\nA\r\nB\r\nC', '', '', 17, 'form_7664a', '', '', '[{\"childIndID\":18,\"parentIndID\":17,\"selectedOp\":\"==\",\"selectedParentValue\":\"2\",\"selectedChildValue\":\"\",\"selectedOutcome\":\"show\",\"crosswalkFile\":\"\",\"crosswalkHasHeader\":false,\"level2IndID\":null,\"childFormat\":\"radio\",\"parentFormat\":\"dropdown\"}]', NULL, 1, -128, '2024-12-09 13:38:21', 0, 0),
(19, 'normal nested currency sub question', 'currency', '', '', 18, 'form_7664a', '', '', NULL, NULL, 1, -128, '2024-12-09 13:38:21', 0, 0),
(20, 'normal nested text sub question', 'text', '', '', 19, 'form_7664a', '', '', NULL, NULL, 1, -128, '2024-12-09 13:38:21', 0, 0),
(21, 'Section 2', '', '', '', NULL, 'form_7664a', NULL, NULL, NULL, NULL, 0, -127, '2024-12-09 13:38:21', 0, 0),
(22, 'numeric parent', 'number', '', '', 21, 'form_7664a', NULL, NULL, NULL, NULL, 1, -128, '2024-12-09 13:38:21', 0, 0),
(23, 'orgchart employee child (show if parent >= 42)', 'orgchart_employee', '', '', 22, 'form_7664a', '', '', '[{\"childIndID\":23,\"parentIndID\":22,\"selectedOp\":\"gte\",\"selectedParentValue\":\"42\",\"selectedChildValue\":\"\",\"selectedOutcome\":\"show\",\"crosswalkFile\":\"\",\"crosswalkHasHeader\":false,\"level2IndID\":null,\"childFormat\":\"orgchart_employee\",\"parentFormat\":\"number\"}]', NULL, 1, -128, '2024-12-09 13:38:21', 0, 0),
(24, 'normal nested date sub question', 'date', '', '', 23, 'form_7664a', '', '', NULL, NULL, 1, -128, '2024-12-09 13:38:21', 0, 0),
(25, 'normal nested multitext sub question', 'textarea', '', '', 23, 'form_7664a', '', '', NULL, NULL, 1, -127, '2024-12-09 13:38:21', 0, 0),
(26, 'checkboxes parent', 'checkboxes\r\nA & B\r\nC & D\r\nE & \"F\"', '', '', 23, 'form_7664a', '', '', NULL, NULL, 1, -126, '2024-12-09 13:38:21', 0, 0),
(27, 'multiselect child (show if parent E & "F")', 'multiselect\r\napple\r\norange\r\nbanana\r\npineapple\r\navocado', '', '', 26, 'form_7664a', '', '', '[{\"childIndID\":27,\"parentIndID\":26,\"selectedOp\":\"==\",\"selectedParentValue\":\"E & "F"\",\"selectedChildValue\":\"\",\"selectedOutcome\":\"show\",\"crosswalkFile\":\"\",\"crosswalkHasHeader\":false,\"level2IndID\":null,\"childFormat\":\"multiselect\",\"parentFormat\":\"checkboxes\"}]', NULL, 1, -128, '2024-12-09 13:38:21', 0, 0),
(28, 'normal nested checkbox child', 'checkbox\r\ntest', '', '', 27, 'form_7664a', '', '', NULL, NULL, 1, -128, '2024-12-09 13:38:21', 0, 0),
(29, 'Header', '', '', '', NULL, 'form_dac2a', NULL, NULL, NULL, NULL, 0, -128, '2024-12-10 14:19:05', 0, 0),
(30, 'parent dropdown', 'dropdown\n\n1\n2\n3', '', '', 29, 'form_dac2a', NULL, NULL, NULL, NULL, 0, -128, '2024-12-10 14:19:35', 0, 0),
(31, 'child text', 'text', '', '', 30, 'form_dac2a', NULL, NULL, '[{\"childIndID\":31,\"parentIndID\":30,\"selectedOp\":\"==\",\"selectedParentValue\":\"3\",\"selectedChildValue\":\"\",\"selectedOutcome\":\"show\",\"crosswalkFile\":\"\",\"crosswalkHasHeader\":false,\"level2IndID\":null,\"childFormat\":\"text\",\"parentFormat\":\"dropdown\"}]', NULL, 1, -128, '2024-12-10 14:19:47', 0, 0),
(32, 'nested sub question', 'text', '', '', 31, 'form_dac2a', NULL, NULL, NULL, NULL, 1, -128, '2024-12-10 14:20:07', 0, 0);

DROP TABLE IF EXISTS `notes`;
CREATE TABLE `notes` (
Expand Down
259 changes: 259 additions & 0 deletions API-tests/form_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,3 +168,262 @@ func TestForm_FilterChildkeys(t *testing.T) {
t.Errorf("./api/form/9/data/tree?x-filterData=child.name child[4].indicatorID = %v, want = %v", m[0].Child[4].IndicatorID, "undefined")
}
}

func TestForm_GetProgress_ReturnValue(t *testing.T) {
/* Setup form_7664a, with staple form_dac2a.
form_7664a has 11 required questions with different formats (format influences logic).
17p controls 18c. 18c has subquestions 19, 20. 18 is visible if 17 is '2'
22p controls 23c. 23c has subquestions 24, 25, (26p, 27c, 28). 23 is visible if 22 is >= '42'
-26p controls 27c. 27c has subquestion 28. 27 is visible if 26 includes 'E & "F"'
form_dac2a has 2 required questions
30p (not required) controls 31c. 31c has subquestion 32. 31 is visisble if 30p is 3
Format information is noted when data is posted */

//create the new request and get the recordID for progress and domodify urls, check intial progress.
postData := url.Values{}
postData.Set("CSRFToken", CsrfToken)
postData.Set("numform_7664a", "1")
postData.Set("title", "TestForm_GetProgressChecking")

res, _ := client.PostForm(RootURL + `api/form/new`, postData)
bodyBytes, _ := io.ReadAll(res.Body)
var response string
json.Unmarshal(bodyBytes, &response)
recordID := string(response)

urlGetProgress := RootURL + "api/form/" + recordID + "/progress"
urlPostDoModify := RootURL + "api/form/" + recordID

got, res := httpGet(urlGetProgress)
if !cmp.Equal(res.StatusCode, 200) {
t.Errorf(urlGetProgress + ", Status Code = %v, want = %v", res.StatusCode, 200)
return
}
want := `"0"`
if !cmp.Equal(got, want) {
t.Errorf("progress check got = %v, want = %v", got, want)
}

//fill 2 visible required questions with values that keep subquestions hidden
postData = url.Values{}
postData.Set("CSRFToken", CsrfToken)
postData.Set("17", "1") //dropdown 1,2,3
res, err := client.PostForm(urlPostDoModify, postData)
if err != nil {
t.Error(urlPostDoModify + "Error sending post request")
}
got, res = httpGet(urlGetProgress)
want = `"50"`
if !cmp.Equal(got, want) {
t.Errorf("progress check got = %v, want = %v", got, want)
}
postData = url.Values{}
postData.Set("CSRFToken", CsrfToken)
postData.Set("22", "10") //numeric
res, err = client.PostForm(urlPostDoModify, postData)
if err != nil {
t.Error(urlPostDoModify + "Error sending post request")
}
got, res = httpGet(urlGetProgress)
want = `"100"`
if !cmp.Equal(got, want) {
t.Errorf("progress check got = %v, want = %v", got, want)
}


//fill 17 to display 18,19,20 (2/5)
postData = url.Values{}
postData.Set("CSRFToken", CsrfToken)
postData.Set("17", "2") //dropdown 1,2,3
res, err = client.PostForm(urlPostDoModify, postData)
if err != nil {
t.Error(urlPostDoModify + "Error sending post request")
}
got, res = httpGet(urlGetProgress)
want = `"40"`
if !cmp.Equal(got, want) {
t.Errorf("progress check got = %v, want = %v", got, want)
}

//fill new visible required questions (3/5, 4/5, 5/5)
postData = url.Values{}
postData.Set("CSRFToken", CsrfToken)
postData.Set("18", "A") //radio A, B, C
res, err = client.PostForm(urlPostDoModify, postData)
if err != nil {
t.Error(urlPostDoModify + "Error sending post request")
}
got, res = httpGet(urlGetProgress)
want = `"60"`
if !cmp.Equal(got, want) {
t.Errorf("progress check got = %v, want = %v", got, want)
}
postData = url.Values{}
postData.Set("CSRFToken", CsrfToken)
postData.Set("19", "2") //currency
res, err = client.PostForm(urlPostDoModify, postData)
if err != nil {
t.Error(urlPostDoModify + "Error sending post request")
}
got, res = httpGet(urlGetProgress)
want = `"80"`
if !cmp.Equal(got, want) {
t.Errorf("progress check got = %v, want = %v", got, want)
}
postData = url.Values{}
postData.Set("CSRFToken", CsrfToken)
postData.Set("20", "test") //single text
res, err = client.PostForm(urlPostDoModify, postData)
if err != nil {
t.Error(urlPostDoModify + "Error sending post request")
}
got, res = httpGet(urlGetProgress)
want = `"100"`
if !cmp.Equal(got, want) {
t.Errorf("progress check got = %v, want = %v", got, want)
}


//fill 22 to display 23,24,25,26 (5/9)
postData = url.Values{}
postData.Set("CSRFToken", CsrfToken)
postData.Set("22", "42") //numeric
res, err = client.PostForm(urlPostDoModify, postData)
if err != nil {
t.Error(urlPostDoModify + "Error sending post request")
}
got, res = httpGet(urlGetProgress)
want = `"56"`
if !cmp.Equal(got, want) {
t.Errorf("progress check got = %v, want = %v", got, want)
}

//fill new visible required questions (6/9, 7/9, 8/9, 9/9)
postData = url.Values{}
postData.Set("CSRFToken", CsrfToken)
postData.Set("23", "1") //orgchart employee
res, err = client.PostForm(urlPostDoModify, postData)
if err != nil {
t.Error(urlPostDoModify + "Error sending post request")
}
got, res = httpGet(urlGetProgress)
want = `"67"`
if !cmp.Equal(got, want) {
t.Errorf("progress check got = %v, want = %v", got, want)
}
postData = url.Values{}
postData.Set("CSRFToken", CsrfToken)
postData.Set("24", "12/04/2024") //date
res, err = client.PostForm(urlPostDoModify, postData)
if err != nil {
t.Error(urlPostDoModify + "Error sending post request")
}
got, res = httpGet(urlGetProgress)
want = `"78"`
if !cmp.Equal(got, want) {
t.Errorf("progress check got = %v, want = %v", got, want)
}
postData = url.Values{}
postData.Set("CSRFToken", CsrfToken)
postData.Set("25", "test") //multiline text
res, err = client.PostForm(urlPostDoModify, postData)
if err != nil {
t.Error(urlPostDoModify + "Error sending post request")
}
got, res = httpGet(urlGetProgress)
want = `"89"`
if !cmp.Equal(got, want) {
t.Errorf("progress check got = %v, want = %v", got, want)
}
postData = url.Values{}
postData.Set("CSRFToken", CsrfToken)
postData.Set("26", "A & B") //checkboxes A & B, C & D, E & "F"
res, err = client.PostForm(urlPostDoModify, postData)
if err != nil {
t.Error(urlPostDoModify + "Error sending post request")
}
got, res = httpGet(urlGetProgress)
want = `"100"`
if !cmp.Equal(got, want) {
t.Errorf("progress check got = %v, want = %v", got, want)
}


//fill 26 to display 27, 28 (9/11)
postData = url.Values{}
postData.Set("CSRFToken", CsrfToken)
postData.Set("26", `E & "F"`) //checkboxes A & B, C & D, E & "F"
res, err = client.PostForm(urlPostDoModify, postData)
if err != nil {
t.Error(urlPostDoModify + "Error sending post request")
}
got, res = httpGet(urlGetProgress)
want = `"82"`
if !cmp.Equal(got, want) {
t.Errorf("progress check got = %v, want = %v", got, want)
}

//fill new visible required questions (10/11, 11/11)
postData = url.Values{}
postData.Set("CSRFToken", CsrfToken)
postData.Set("27", "apple") //multiselect apple, orange, banana, pineapple, avocado
res, err = client.PostForm(urlPostDoModify, postData)
if err != nil {
t.Error(urlPostDoModify + "Error sending post request")
}
got, res = httpGet(urlGetProgress)
want = `"91"`
if !cmp.Equal(got, want) {
t.Errorf("progress check got = %v, want = %v", got, want)
}
postData = url.Values{}
postData.Set("CSRFToken", CsrfToken)
postData.Set("28", "test") //checkbox, label is 'test'
res, err = client.PostForm(urlPostDoModify, postData)
if err != nil {
t.Error(urlPostDoModify + "Error sending post request")
}
got, res = httpGet(urlGetProgress)
want = `"100"`
if !cmp.Equal(got, want) {
t.Errorf("progress check got = %v, want = %v", got, want)
}

//fill staple 30 to display 31c, 32 (11/13)
postData = url.Values{}
postData.Set("CSRFToken", CsrfToken)
postData.Set("30", "3") //dropdown 1,2,3
res, err = client.PostForm(urlPostDoModify, postData)
if err != nil {
t.Error(urlPostDoModify + "Error sending post request")
}
got, res = httpGet(urlGetProgress)
want = `"85"`
if !cmp.Equal(got, want) {
t.Errorf("progress check got = %v, want = %v", got, want)
}
postData = url.Values{}
postData.Set("CSRFToken", CsrfToken)
postData.Set("31", "test 31") //text
res, err = client.PostForm(urlPostDoModify, postData)
if err != nil {
t.Error(urlPostDoModify + "Error sending post request")
}
got, res = httpGet(urlGetProgress)
want = `"92"`
if !cmp.Equal(got, want) {
t.Errorf("progress check got = %v, want = %v", got, want)
}
postData = url.Values{}
postData.Set("CSRFToken", CsrfToken)
postData.Set("32", "test 32") //text
res, err = client.PostForm(urlPostDoModify, postData)
if err != nil {
t.Error(urlPostDoModify + "Error sending post request")
}
got, res = httpGet(urlGetProgress)
want = `"100"`
if !cmp.Equal(got, want) {
t.Errorf("progress check got = %v, want = %v", got, want)
}
}
Loading