From 51d46b9295fefd5872f35305fd2285624e0e620e Mon Sep 17 00:00:00 2001 From: Gabriela Moura Date: Wed, 15 Feb 2023 23:11:06 -0300 Subject: [PATCH] :sparkles: add teste ao connection na model e completa 100% de coverage --- tests/unit/Models/connection.test.ts | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 tests/unit/Models/connection.test.ts diff --git a/tests/unit/Models/connection.test.ts b/tests/unit/Models/connection.test.ts new file mode 100644 index 0000000..1e6d64c --- /dev/null +++ b/tests/unit/Models/connection.test.ts @@ -0,0 +1,22 @@ +import { expect } from 'chai'; +import Connection from '../../../src/Models/Connection'; + +describe('connectToDatabase', function () { + it('should connect to the database successfully', async function () { + try { + const result = await Connection(); + expect(result).to.be.an('object'); + expect(result.connections[0].readyState).to.equal(1); + } catch (error) { + console.log(error); + } + }); + + it('should return an error if the connection fails', async function () { + try { + await Connection('mongodb://localhost:27017/invalid-database'); + } catch (error) { + expect(error).to.be.an('error'); + } + }); +});