From 7905f219cff6fbf888b79da187ce327854fae77d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gabrielle=20Guimar=C3=A3es=20de=20Oliveira?= Date: Sat, 12 Aug 2023 02:43:09 -0300 Subject: [PATCH] test: add remaining tests for qr code (#53) --- src/test/kotlin/PixQrCodeTests.kt | 143 ++++++++++++++++++++++++++++++ 1 file changed, 143 insertions(+) diff --git a/src/test/kotlin/PixQrCodeTests.kt b/src/test/kotlin/PixQrCodeTests.kt index 7023402..6951ed1 100644 --- a/src/test/kotlin/PixQrCodeTests.kt +++ b/src/test/kotlin/PixQrCodeTests.kt @@ -1,3 +1,5 @@ +@file:Suppress("MaxLineLength", "LongMethod") + package br.com.openpix.sdk import io.ktor.client.engine.mock.* @@ -61,4 +63,145 @@ class PixQrCodeTests { assertThat(response).isEqualTo(PixQrCodeResponse(pixQrCode = pixQrCode)) } } + + @Test + fun `test get pix qr code page async`() { + val engine = MockEngine { + respond( + content = ByteReadChannel( + """ + { + "pixQrCodes": [ + { + "value": 100, + "name": "dummy", + "comment": "good", + "correlationID": "9134e286-6f71-427a-bf00-241681624586", + "identifier": "zr7833b4060c488a9b0f89811", + "paymentLinkID": "7777a23s-6f71-427a-bf00-241681624586", + "paymentLinkUrl": "https://openpix.com.br/pay/9134e286-6f71-427a-bf00-241681624586", + "qrCodeImage": "https://api.openpix.com.br/openpi...", + "createdAt": "2021-03-02T17:28:51.882Z", + "updatedAt": "2021-03-02T17:28:51.882Z", + "brCode": "000201010212261060014br.gov.bcb..." + } + ], + "pageInfo": { + "errors": [], + "skip": 0, + "limit": 1, + "totalCount": 1, + "hasNextPage": false, + "hasPreviousPage": false + } + } + """.trimIndent(), + ), + headers = headersOf("Content-Type" to listOf("application/json")), + status = HttpStatusCode.OK, + ) + } + val httpClient = createDefaultHttpClient(engine, "", "", createJson()) + val client = WooviSDK("", client = httpClient) + + @Suppress("MaxLineLength") + val pixQrCode = PixQrCode( + name = "dummy", + identifier = "zr7833b4060c488a9b0f89811", + correlationID = "9134e286-6f71-427a-bf00-241681624586", + paymentLinkID = "7777a23s-6f71-427a-bf00-241681624586", + paymentLinkUrl = "https://openpix.com.br/pay/9134e286-6f71-427a-bf00-241681624586", + createdAt = "2021-03-02T17:28:51.882Z", + updatedAt = "2021-03-02T17:28:51.882Z", + brCode = "000201010212261060014br.gov.bcb...", + qrCodeImage = "https://api.openpix.com.br/openpi...", + ) + + runBlocking { + val response = withContext(Dispatchers.IO) { + client.pixQrCodes().items() + } + + val pageInfo = withContext(Dispatchers.IO) { + client.pixQrCodes().pageInfo() + } + + assertThat(response).isEqualTo(listOf(pixQrCode)) + assertThat(pageInfo).isEqualTo( + PageInfo( + errors = listOf(), + skip = 0, + limit = 1, + totalCount = 1, + hasNextPage = false, + hasPreviousPage = false, + ), + ) + } + } + + @Test + fun `test create pix qr code async`() { + val engine = MockEngine { + respond( + content = ByteReadChannel( + """ + { + "pixQrCode": { + "value": 100, + "name": "dummy", + "comment": "good", + "correlationID": "9134e286-6f71-427a-bf00-241681624586", + "identifier": "zr7833b4060c488a9b0f89811", + "paymentLinkID": "7777a23s-6f71-427a-bf00-241681624586", + "paymentLinkUrl": "https://openpix.com.br/pay/9134e286-6f71-427a-bf00-241681624586", + "qrCodeImage": "https://api.openpix.com.br/openpi...", + "createdAt": "2021-03-02T17:28:51.882Z", + "updatedAt": "2021-03-02T17:28:51.882Z", + "brCode": "000201010212261060014br.gov.bcb..." + }, + "brCode": "000201010212261060014br.gov.bcb...", + "correlationID": "9134e286-6f71-427a-bf00-241681624586" + } + """.trimIndent(), + ), + headers = headersOf("Content-Type" to listOf("application/json")), + status = HttpStatusCode.OK, + ) + } + val httpClient = createDefaultHttpClient(engine, "", "", createJson()) + val client = WooviSDK("", client = httpClient) + + @Suppress("MaxLineLength") + val pixQrCode = PixQrCode( + name = "dummy", + identifier = "zr7833b4060c488a9b0f89811", + correlationID = "9134e286-6f71-427a-bf00-241681624586", + paymentLinkID = "7777a23s-6f71-427a-bf00-241681624586", + paymentLinkUrl = "https://openpix.com.br/pay/9134e286-6f71-427a-bf00-241681624586", + createdAt = "2021-03-02T17:28:51.882Z", + updatedAt = "2021-03-02T17:28:51.882Z", + brCode = "000201010212261060014br.gov.bcb...", + qrCodeImage = "https://api.openpix.com.br/openpi...", + ) + + runBlocking { + val response = withContext(Dispatchers.IO) { + client.createPixQrCode { + correlationID = "9134e286-6f71-427a-bf00-241681624586" + identifier = "zr7833b4060c488a9b0f89811" + name = "dummy" + value = 100 + } + } + + assertThat(response).isEqualTo( + PixQrCodeResponse( + pixQrCode = pixQrCode, + brCode = "000201010212261060014br.gov.bcb...", + correlationID = "9134e286-6f71-427a-bf00-241681624586", + ), + ) + } + } }