From 772a02acf1dc9a32e699b9a76742aa0562ec4d4d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marco=20Ch=C3=A1vez?= Date: Sun, 21 Apr 2024 19:23:36 -0600 Subject: [PATCH 1/5] Add test case uniqueJobMergeData --- test/tests/jobs/CreateJobTest.cpp | 75 ++++++++++++++++++++++++------- 1 file changed, 59 insertions(+), 16 deletions(-) diff --git a/test/tests/jobs/CreateJobTest.cpp b/test/tests/jobs/CreateJobTest.cpp index f59a43e76..88a72f09f 100644 --- a/test/tests/jobs/CreateJobTest.cpp +++ b/test/tests/jobs/CreateJobTest.cpp @@ -10,22 +10,23 @@ struct CreateJobTest : tpunit::TestFixture { CreateJobTest() : tpunit::TestFixture("CreateJob", BEFORE_CLASS(CreateJobTest::setupClass), - TEST(CreateJobTest::create), - TEST(CreateJobTest::createWithHttp), - TEST(CreateJobTest::createWithPriority), - TEST(CreateJobTest::createWithData), - TEST(CreateJobTest::createWithRepeat), - TEST(CreateJobTest::uniqueJob), - TEST(CreateJobTest::createWithBadData), - TEST(CreateJobTest::createWithBadRepeat), - TEST(CreateJobTest::createChildWithQueuedParent), - TEST(CreateJobTest::createChildWithRunningGrandparent), - TEST(CreateJobTest::retryRecurringJobs), - TEST(CreateJobTest::retryWithMalformedValue), - TEST(CreateJobTest::retryUnique), - TEST(CreateJobTest::retryLifecycle), - TEST(CreateJobTest::retryWithChildren), - TEST(CreateJobTest::getManualJobWithRetryAfter), + // TEST(CreateJobTest::create), + // TEST(CreateJobTest::createWithHttp), + // TEST(CreateJobTest::createWithPriority), + // TEST(CreateJobTest::createWithData), + // TEST(CreateJobTest::createWithRepeat), + // TEST(CreateJobTest::uniqueJob), + TEST(CreateJobTest::uniqueJobMergeData), + // TEST(CreateJobTest::createWithBadData), + // TEST(CreateJobTest::createWithBadRepeat), + // TEST(CreateJobTest::createChildWithQueuedParent), + // TEST(CreateJobTest::createChildWithRunningGrandparent), + // TEST(CreateJobTest::retryRecurringJobs), + // TEST(CreateJobTest::retryWithMalformedValue), + // TEST(CreateJobTest::retryUnique), + // TEST(CreateJobTest::retryLifecycle), + // TEST(CreateJobTest::retryWithChildren), + // TEST(CreateJobTest::getManualJobWithRetryAfter), AFTER(CreateJobTest::tearDown), AFTER_CLASS(CreateJobTest::tearDownClass)) { } @@ -165,6 +166,48 @@ struct CreateJobTest : tpunit::TestFixture { ASSERT_EQUAL(stol(originalJob[0][9]), 0); } + // Create a unique job + // Then try to recreate the job with the some data + // Make sure the new data is saved + void uniqueJobMergeData() { + // Create a unique job + SData command("CreateJob"); + string jobName = "blabla"; + command["name"] = jobName; + command["data"] = "{\"a\":1, \"b\":2}"; + command["unique"] = "true"; + STable response = tester->executeWaitVerifyContentTable(command); + int64_t jobID = stol(response["jobID"]); + ASSERT_GREATER_THAN(jobID, 0); + + SQResult originalJob; + tester->readDB("SELECT created, jobID, state, name, nextRun, lastRun, repeat, data, priority, parentJobID FROM jobs WHERE jobID = " + response["jobID"] + ";", originalJob); + + // Try to recreate the job with the same data. + response = tester->executeWaitVerifyContentTable(command); + ASSERT_EQUAL(stol(response["jobID"]), jobID); + + // Try to recreate the job with new data, it should get updated. + command["data"] = "{\"c\":3, \"d\":4}"; + response = tester->executeWaitVerifyContentTable(command); + ASSERT_EQUAL(stol(response["jobID"]), jobID); + + SQResult updatedJob; + tester->readDB("SELECT created, jobID, state, name, nextRun, lastRun, repeat, data, priority, parentJobID FROM jobs WHERE jobID = " + response["jobID"] + ";", updatedJob); + ASSERT_EQUAL(updatedJob.size(), 1); + // Assert the values are what we expect + ASSERT_EQUAL(updatedJob[0][0], originalJob[0][0]); + ASSERT_EQUAL(updatedJob[0][1], originalJob[0][1]); + ASSERT_EQUAL(updatedJob[0][2], originalJob[0][2]); + ASSERT_EQUAL(updatedJob[0][3], originalJob[0][3]); + ASSERT_EQUAL(updatedJob[0][4], originalJob[0][4]); + ASSERT_EQUAL(updatedJob[0][5], originalJob[0][5]); + ASSERT_EQUAL(updatedJob[0][6], originalJob[0][6]); + ASSERT_EQUAL(updatedJob[0][7], "{\"a\":1,\"b\":2,\"c\":3,\"d\":4}"); + ASSERT_EQUAL(updatedJob[0][8], originalJob[0][8]); + ASSERT_EQUAL(updatedJob[0][9], originalJob[0][9]); + } + // Create a unique job // Then try to recreate the job with the some data // Make sure the new data is saved From 115dcdd30f5ecba48b5d53aa30a195c18f7f74e6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marco=20Ch=C3=A1vez?= Date: Sun, 21 Apr 2024 19:26:45 -0600 Subject: [PATCH 2/5] Add case for nestedObject --- test/tests/jobs/CreateJobTest.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test/tests/jobs/CreateJobTest.cpp b/test/tests/jobs/CreateJobTest.cpp index 88a72f09f..aa3995fe4 100644 --- a/test/tests/jobs/CreateJobTest.cpp +++ b/test/tests/jobs/CreateJobTest.cpp @@ -174,7 +174,7 @@ struct CreateJobTest : tpunit::TestFixture { SData command("CreateJob"); string jobName = "blabla"; command["name"] = jobName; - command["data"] = "{\"a\":1, \"b\":2}"; + command["data"] = "{\"a\":1, \"b\":2, \"nestedObject\": {\"A\":1, \"B\":2}}"; command["unique"] = "true"; STable response = tester->executeWaitVerifyContentTable(command); int64_t jobID = stol(response["jobID"]); @@ -188,7 +188,7 @@ struct CreateJobTest : tpunit::TestFixture { ASSERT_EQUAL(stol(response["jobID"]), jobID); // Try to recreate the job with new data, it should get updated. - command["data"] = "{\"c\":3, \"d\":4}"; + command["data"] = "{\"c\":3, \"d\":4, \"nestedObject\": {\"C\":3, \"D\":4}}"; response = tester->executeWaitVerifyContentTable(command); ASSERT_EQUAL(stol(response["jobID"]), jobID); @@ -203,7 +203,7 @@ struct CreateJobTest : tpunit::TestFixture { ASSERT_EQUAL(updatedJob[0][4], originalJob[0][4]); ASSERT_EQUAL(updatedJob[0][5], originalJob[0][5]); ASSERT_EQUAL(updatedJob[0][6], originalJob[0][6]); - ASSERT_EQUAL(updatedJob[0][7], "{\"a\":1,\"b\":2,\"c\":3,\"d\":4}"); + ASSERT_EQUAL(updatedJob[0][7], "{\"a\":1,\"b\":2,\"nestedObject\":{\"A\":1,\"B\":2,\"C\":3,\"D\":4},\"c\":3,\"d\":4}"); ASSERT_EQUAL(updatedJob[0][8], originalJob[0][8]); ASSERT_EQUAL(updatedJob[0][9], originalJob[0][9]); } From 93692e2f6b0efe4e2a93c58f79c5a3d461a2a552 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marco=20Ch=C3=A1vez?= Date: Sun, 21 Apr 2024 19:28:56 -0600 Subject: [PATCH 3/5] Add test for nestedArray --- test/tests/jobs/CreateJobTest.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test/tests/jobs/CreateJobTest.cpp b/test/tests/jobs/CreateJobTest.cpp index aa3995fe4..f17febe17 100644 --- a/test/tests/jobs/CreateJobTest.cpp +++ b/test/tests/jobs/CreateJobTest.cpp @@ -174,7 +174,7 @@ struct CreateJobTest : tpunit::TestFixture { SData command("CreateJob"); string jobName = "blabla"; command["name"] = jobName; - command["data"] = "{\"a\":1, \"b\":2, \"nestedObject\": {\"A\":1, \"B\":2}}"; + command["data"] = "{\"a\":1, \"b\":2, \"nestedObject\": {\"A\":1, \"B\":2}, \"nestedArray\":[1,2]}"; command["unique"] = "true"; STable response = tester->executeWaitVerifyContentTable(command); int64_t jobID = stol(response["jobID"]); @@ -188,7 +188,7 @@ struct CreateJobTest : tpunit::TestFixture { ASSERT_EQUAL(stol(response["jobID"]), jobID); // Try to recreate the job with new data, it should get updated. - command["data"] = "{\"c\":3, \"d\":4, \"nestedObject\": {\"C\":3, \"D\":4}}"; + command["data"] = "{\"c\":3, \"d\":4, \"nestedObject\": {\"C\":3, \"D\":4}, \"nestedArray\":[3,4]}"; response = tester->executeWaitVerifyContentTable(command); ASSERT_EQUAL(stol(response["jobID"]), jobID); @@ -203,7 +203,7 @@ struct CreateJobTest : tpunit::TestFixture { ASSERT_EQUAL(updatedJob[0][4], originalJob[0][4]); ASSERT_EQUAL(updatedJob[0][5], originalJob[0][5]); ASSERT_EQUAL(updatedJob[0][6], originalJob[0][6]); - ASSERT_EQUAL(updatedJob[0][7], "{\"a\":1,\"b\":2,\"nestedObject\":{\"A\":1,\"B\":2,\"C\":3,\"D\":4},\"c\":3,\"d\":4}"); + ASSERT_EQUAL(updatedJob[0][7], "{\"a\":1,\"b\":2,\"nestedObject\":{\"A\":1,\"B\":2,\"C\":3,\"D\":4},\"nestedArray\":[3,4],\"c\":3,\"d\":4}"); ASSERT_EQUAL(updatedJob[0][8], originalJob[0][8]); ASSERT_EQUAL(updatedJob[0][9], originalJob[0][9]); } From 45d2db6ad1291f9f418ecd8f2e76626b0d3d9cb0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marco=20Ch=C3=A1vez?= Date: Sun, 21 Apr 2024 19:29:42 -0600 Subject: [PATCH 4/5] Enable the rest of the tests --- test/tests/jobs/CreateJobTest.cpp | 32 +++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/test/tests/jobs/CreateJobTest.cpp b/test/tests/jobs/CreateJobTest.cpp index f17febe17..abb7df2ad 100644 --- a/test/tests/jobs/CreateJobTest.cpp +++ b/test/tests/jobs/CreateJobTest.cpp @@ -10,23 +10,23 @@ struct CreateJobTest : tpunit::TestFixture { CreateJobTest() : tpunit::TestFixture("CreateJob", BEFORE_CLASS(CreateJobTest::setupClass), - // TEST(CreateJobTest::create), - // TEST(CreateJobTest::createWithHttp), - // TEST(CreateJobTest::createWithPriority), - // TEST(CreateJobTest::createWithData), - // TEST(CreateJobTest::createWithRepeat), - // TEST(CreateJobTest::uniqueJob), + TEST(CreateJobTest::create), + TEST(CreateJobTest::createWithHttp), + TEST(CreateJobTest::createWithPriority), + TEST(CreateJobTest::createWithData), + TEST(CreateJobTest::createWithRepeat), + TEST(CreateJobTest::uniqueJob), TEST(CreateJobTest::uniqueJobMergeData), - // TEST(CreateJobTest::createWithBadData), - // TEST(CreateJobTest::createWithBadRepeat), - // TEST(CreateJobTest::createChildWithQueuedParent), - // TEST(CreateJobTest::createChildWithRunningGrandparent), - // TEST(CreateJobTest::retryRecurringJobs), - // TEST(CreateJobTest::retryWithMalformedValue), - // TEST(CreateJobTest::retryUnique), - // TEST(CreateJobTest::retryLifecycle), - // TEST(CreateJobTest::retryWithChildren), - // TEST(CreateJobTest::getManualJobWithRetryAfter), + TEST(CreateJobTest::createWithBadData), + TEST(CreateJobTest::createWithBadRepeat), + TEST(CreateJobTest::createChildWithQueuedParent), + TEST(CreateJobTest::createChildWithRunningGrandparent), + TEST(CreateJobTest::retryRecurringJobs), + TEST(CreateJobTest::retryWithMalformedValue), + TEST(CreateJobTest::retryUnique), + TEST(CreateJobTest::retryLifecycle), + TEST(CreateJobTest::retryWithChildren), + TEST(CreateJobTest::getManualJobWithRetryAfter), AFTER(CreateJobTest::tearDown), AFTER_CLASS(CreateJobTest::tearDownClass)) { } From 752f986b1c9bb1f30e22c9ce9a4ad6c09b56efbd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marco=20Ch=C3=A1vez?= Date: Mon, 22 Apr 2024 11:42:41 -0600 Subject: [PATCH 5/5] Update test/tests/jobs/CreateJobTest.cpp Co-authored-by: Carlos Martins --- test/tests/jobs/CreateJobTest.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/tests/jobs/CreateJobTest.cpp b/test/tests/jobs/CreateJobTest.cpp index abb7df2ad..789c0cd31 100644 --- a/test/tests/jobs/CreateJobTest.cpp +++ b/test/tests/jobs/CreateJobTest.cpp @@ -167,7 +167,7 @@ struct CreateJobTest : tpunit::TestFixture { } // Create a unique job - // Then try to recreate the job with the some data + // Then try to recreate the job with the same data // Make sure the new data is saved void uniqueJobMergeData() { // Create a unique job