From 921801d8703504f2c6e7ce6c5daeaf828f52faf1 Mon Sep 17 00:00:00 2001
From: Jayaprakash8887 <Jayaprakash.narayanaswamy@tarento.com>
Date: Tue, 6 Sep 2022 15:13:19 +0530
Subject: [PATCH] Issue #KN-257 feat: Content Release DIAL codes API refactor.

---
 .../content/dial/DIALManagerTest.scala        | 40 ++++++++++++++++++-
 1 file changed, 39 insertions(+), 1 deletion(-)

diff --git a/content-api/content-actors/src/test/scala/org/sunbird/content/dial/DIALManagerTest.scala b/content-api/content-actors/src/test/scala/org/sunbird/content/dial/DIALManagerTest.scala
index 9457a4173..1ea02a355 100644
--- a/content-api/content-actors/src/test/scala/org/sunbird/content/dial/DIALManagerTest.scala
+++ b/content-api/content-actors/src/test/scala/org/sunbird/content/dial/DIALManagerTest.scala
@@ -283,6 +283,25 @@ class DIALManagerTest extends AsyncFlatSpec with Matchers with AsyncMockFactory
 		})
 	}
 
+	"release DIAL" should "update content with reservedDialcodes excluding the number of dialcodes mentioned in count" in {
+		(oec.httpUtil _).expects().returns(httpUtil)
+		(oec.graphService _).expects().returns(graphDB).anyNumberOfTimes()
+
+		val nodes: util.List[Node] = getCategoryNode()
+		(graphDB.getNodeByUniqueIds(_: String, _: SearchCriteria)).expects(*, *).returns(Future(nodes)).anyNumberOfTimes()
+
+		val contentId: String = "do_123456"
+		(graphDB.getNodeByUniqueId(_: String, _: String, _: Boolean, _: Request)).expects(*, *, *, *).returns(Future(getNode(contentId))).anyNumberOfTimes()
+		(graphDB.getNodeProperty(_: String, _: String, _: String)).expects(*, *, *).returns(Future(new Property("versionKey", new org.neo4j.driver.internal.value.StringValue("1234"))))
+		(graphDB.upsertNode(_: String, _: Node, _: Request)).expects(*, *, *).returns(Future(getNode(contentId)))
+
+		val request = getReleaseDIALRequest(contentId)
+
+		val response = DIALManager.release(request)
+		response.map(result => {
+			assert(result.getResponseCode.toString=="OK")
+		})
+	}
 
 	def getDIALSearchResponse:Response = {
 		val resString = "{\n  \"id\": \"sunbird.dialcode.search\",\n  \"ver\": \"3.0\",\n  \"ts\": \"2020-04-21T19:39:14ZZ\",\n  \"params\": {\n    \"resmsgid\": \"1dfcc25b-6c37-49f8-a6c3-7185063e8752\",\n    \"msgid\": null,\n    \"err\": null,\n    \"status\": \"successful\",\n    \"errmsg\": null\n  },\n  \"responseCode\": \"OK\",\n  \"result\": {\n    \"dialcodes\": [\n      {\n        \"dialcode_index\": 7609876,\n        \"identifier\": \"N4Z7D5\",\n        \"channel\": \"testr01\",\n        \"batchcode\": \"testPub0001.20200421T193801\",\n        \"publisher\": \"testPub0001\",\n        \"generated_on\": \"2020-04-21T19:38:01.603+0000\",\n        \"status\": \"Draft\",\n        \"objectType\": \"DialCode\"\n      },\n      {\n        \"dialcode_index\": 7610113,\n        \"identifier\": \"E8B7Z6\",\n        \"channel\": \"testr01\",\n        \"batchcode\": \"testPub0001.20200421T193801\",\n        \"publisher\": \"testPub0001\",\n        \"generated_on\": \"2020-04-21T19:38:01.635+0000\",\n        \"status\": \"Draft\",\n        \"objectType\": \"DialCode\"\n      },\n      {\n        \"dialcode_index\": 7610117,\n        \"identifier\": \"R4X2P2\",\n        \"channel\": \"testr01\",\n        \"batchcode\": \"testPub0001.20200421T193801\",\n        \"publisher\": \"testPub0001\",\n        \"generated_on\": \"2020-04-21T19:38:01.637+0000\",\n        \"status\": \"Draft\",\n        \"objectType\": \"DialCode\"\n      },\n      {\n        \"dialcode_index\": 7610961,\n        \"identifier\": \"L4A6W8\",\n        \"channel\": \"testr01\",\n        \"batchcode\": \"testPub0001.20200421T193801\",\n        \"publisher\": \"testPub0001\",\n        \"generated_on\": \"2020-04-21T19:38:01.734+0000\",\n        \"status\": \"Draft\",\n        \"objectType\": \"DialCode\"\n      },\n      {\n        \"dialcode_index\": 7611164,\n        \"identifier\": \"D2E1J9\",\n        \"channel\": \"testr01\",\n        \"batchcode\": \"testPub0001.20200421T193801\",\n        \"publisher\": \"testPub0001\",\n        \"generated_on\": \"2020-04-21T19:38:01.759+0000\",\n        \"status\": \"Draft\",\n        \"objectType\": \"DialCode\"\n      }\n    ],\n    \"count\": 5\n  }\n}";
@@ -561,7 +580,7 @@ class DIALManagerTest extends AsyncFlatSpec with Matchers with AsyncMockFactory
 	def getReserveRequest():util.Map[String, AnyRef] = {
 		val reqMap : java.util.Map[String, AnyRef] = new util.HashMap[String, AnyRef](){
 			put("dialcodes", new util.HashMap[String, AnyRef](){
-				put("count", 2.asInstanceOf[Integer])
+				put("count", 12.asInstanceOf[Integer])
 				put("qrCodeSpec", new util.HashMap[String, AnyRef](){
 					put("errorCorrectionLevel", "H")
 				})
@@ -570,6 +589,25 @@ class DIALManagerTest extends AsyncFlatSpec with Matchers with AsyncMockFactory
 		reqMap
 	}
 
+	def getReleaseDIALRequest(identifier: String): Request = {
+		val request = new Request()
+		request.setObjectType("Content")
+		request.setContext(getContext())
+		request.getContext.put("identifier",identifier)
+		request.put("identifier",identifier)
+		request.putAll(getReserveRequest())
+		request
+	}
+
+	def getReleaseRequest():util.Map[String, AnyRef] = {
+		val reqMap : java.util.Map[String, AnyRef] = new util.HashMap[String, AnyRef](){
+			put("dialcodes", new util.HashMap[String, AnyRef](){
+				put("count", 2.asInstanceOf[Integer])
+			})
+		}
+		reqMap
+	}
+
 	def getGenerateDIALResponse:Response = {
 		val resString = "{\"id\": \"api.dialcode.generate\",\"ver\": \"1.0\",\"ts\": \"2022-07-05T09:47:26.000Z\",\"params\": {\"resmsgid\": \"79eb8b00-fc47-11ec-af25-0f53946b16ec\",\"msgid\": \"79be1260-fc47-11ec-8c03-63ca5ce41074\",\"status\": \"successful\",\"err\": null,\"errmsg\": null},\"responseCode\": \"OK\",\"result\": {\"dialcodes\": [\"K2C3R6\",\"H2E8F9\"],\"count\": 2,\"batchcode\": \"do_11357423520695910411\",\"publisher\": null}}"
 		JsonUtils.deserialize(resString, classOf[Response])
-- 
GitLab