Skip to content

Commit

Permalink
Implementação de testes de validação de JSON Schema
Browse files Browse the repository at this point in the history
  • Loading branch information
thinogueiras committed Mar 5, 2024
1 parent a07a196 commit 9fa1697
Show file tree
Hide file tree
Showing 4 changed files with 331 additions and 0 deletions.
70 changes: 70 additions & 0 deletions resources/schemas/account.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
{
"$schema": "https://json-schema.org/draft/2019-09/schema",
"$id": "http://example.com/example.json",
"type": "array",
"default": [],
"title": "Root Schema",
"items": {
"type": "object",
"title": "A Schema",
"required": [
"id",
"nome",
"visivel",
"usuario_id"
],
"properties": {
"id": {
"type": "integer",
"title": "The id Schema",
"examples": [
2054551,
2054552
]
},
"nome": {
"type": "string",
"title": "The nome Schema",
"examples": [
"Conta mesmo nome",
"Conta para movimentacoes",
"Conta com movimentacao",
"Conta para saldo",
"Conta para extrato",
"Conta Alterada com Sucesso",
"Conta de investimentos"
]
},
"visivel": {
"type": "boolean",
"title": "The visivel Schema",
"examples": [
true
]
},
"usuario_id": {
"type": "integer",
"title": "The usuario_id Schema",
"examples": [
34767
]
}
}
},
"examples": [
[
{
"id": 2054551,
"nome": "Conta mesmo nome",
"visivel": true,
"usuario_id": 34767
},
{
"id": 2054552,
"nome": "Conta para movimentacoes",
"visivel": true,
"usuario_id": 34767
}
]
]
}
59 changes: 59 additions & 0 deletions resources/schemas/balance.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
{
"$schema": "https://json-schema.org/draft/2019-09/schema",
"$id": "http://example.com/example.json",
"type": "array",
"default": [],
"title": "Root Schema",
"items": {
"type": "object",
"title": "A Schema",
"required": [
"conta_id",
"conta",
"saldo"
],
"properties": {
"conta_id": {
"type": "integer",
"title": "The conta_id Schema",
"examples": [
2054722,
2054723
]
},
"conta": {
"type": "string",
"title": "The conta Schema",
"examples": [
"Conta para movimentacoes",
"Conta com movimentacao",
"Conta para saldo",
"Conta para extrato"
]
},
"saldo": {
"type": "string",
"title": "The saldo Schema",
"examples": [
"-1500.00",
"534.00",
"-220.00"
]
}
}
},
"examples": [
[
{
"conta_id": 2054722,
"conta": "Conta para movimentacoes",
"saldo": "-1500.00"
},
{
"conta_id": 2054724,
"conta": "Conta para saldo",
"saldo": "534.00"
}
]
]
}
180 changes: 180 additions & 0 deletions resources/schemas/movement.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,180 @@
{
"$schema": "https://json-schema.org/draft/2019-09/schema",
"$id": "http://example.com/example.json",
"type": "array",
"default": [],
"title": "Root Schema",
"items": {
"type": "object",
"title": "A Schema",
"required": [
"id",
"descricao",
"envolvido",
"observacao",
"tipo",
"data_transacao",
"data_pagamento",
"valor",
"status",
"conta_id",
"usuario_id",
"transferencia_id",
"parcelamento_id"
],
"properties": {
"id": {
"type": "integer",
"title": "The id Schema",
"examples": [
1926111,
1926112,
1926113,
1926114,
1926115,
1926116
]
},
"descricao": {
"type": "string",
"title": "The descricao Schema",
"examples": [
"Movimentacao para exclusao",
"Movimentacao de conta",
"Movimentacao 1, calculo saldo",
"Movimentacao 2, calculo saldo",
"Movimentacao 3, calculo saldo",
"Movimentacao para extrato"
]
},
"envolvido": {
"type": "string",
"title": "The envolvido Schema",
"examples": [
"AAA",
"BBB",
"CCC",
"DDD",
"EEE",
"FFF"
]
},
"observacao": {
"type": "null",
"title": "The observacao Schema",
"examples": [
null
]
},
"tipo": {
"type": "string",
"title": "The tipo Schema",
"examples": [
"DESP",
"REC"
]
},
"data_transacao": {
"type": "string",
"title": "The data_transacao Schema",
"examples": [
"2024-03-04T03:00:00.000Z"
]
},
"data_pagamento": {
"type": "string",
"title": "The data_pagamento Schema",
"examples": [
"2024-03-04T03:00:00.000Z"
]
},
"valor": {
"type": [
"integer",
"string"
],
"title": "The valor Schema",
"examples": [
1500,
"3500.00",
1000,
"1534.00",
220
]
},
"status": {
"type": "boolean",
"title": "The status Schema",
"examples": [
true,
false
]
},
"conta_id": {
"type": "integer",
"title": "The conta_id Schema",
"examples": [
2054740,
2054741,
2054742,
2054743
]
},
"usuario_id": {
"type": "integer",
"title": "The usuario_id Schema",
"examples": [
34767
]
},
"transferencia_id": {
"type": "null",
"title": "The transferencia_id Schema",
"examples": [
null
]
},
"parcelamento_id": {
"type": "null",
"title": "The parcelamento_id Schema",
"examples": [
null
]
}
}
},
"examples": [
[
{
"id": 1926111,
"descricao": "Movimentacao para exclusao",
"envolvido": "AAA",
"observacao": null,
"tipo": "DESP",
"data_transacao": "2024-03-04T03:00:00.000Z",
"data_pagamento": "2024-03-04T03:00:00.000Z",
"valor": 1500,
"status": true,
"conta_id": 2054740,
"usuario_id": 34767,
"transferencia_id": null,
"parcelamento_id": null
},
{
"id": 1926112,
"descricao": "Movimentacao de conta",
"envolvido": "BBB",
"observacao": null,
"tipo": "DESP",
"data_transacao": "2024-03-04T03:00:00.000Z",
"data_pagamento": "2024-03-04T03:00:00.000Z",
"valor": 1500,
"status": true,
"conta_id": 2054741,
"usuario_id": 34767,
"transferencia_id": null,
"parcelamento_id": null
}
]
]
}
22 changes: 22 additions & 0 deletions tests/schema.robot
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
*** Settings ***
Documentation JSON Schema Tests
Resource ../resources/base.resource

Suite Setup Setup

*** Test Cases ***
Deve validar o JSON Schema para Contas
${response} Get All Accounts

Validate Json By Schema File ${response.json()} ${EXECDIR}/resources/schemas/account.json

Deve validar o JSON Schema para Saldo
${response} Get All Balances

Validate Json By Schema File ${response.json()} ${EXECDIR}/resources/schemas/balance.json

Deve validar o JSON Schema para Movimentações
${response} Get All Movements

Validate Json By Schema File ${response.json()} ${EXECDIR}/resources/schemas/movement.json

0 comments on commit 9fa1697

Please sign in to comment.