From e094fe44562748b66311dd8668cdfe410e00ebd1 Mon Sep 17 00:00:00 2001 From: Carlos Jimenez <=> Date: Tue, 7 Aug 2018 15:04:06 +0200 Subject: [PATCH] #568 ticket-packaging.js Backend unit tests --- .../models/specs/ticket-packaging.spec.js | 38 +++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 services/ticket/common/models/specs/ticket-packaging.spec.js diff --git a/services/ticket/common/models/specs/ticket-packaging.spec.js b/services/ticket/common/models/specs/ticket-packaging.spec.js new file mode 100644 index 000000000..c1f0f5897 --- /dev/null +++ b/services/ticket/common/models/specs/ticket-packaging.spec.js @@ -0,0 +1,38 @@ +const app = require(`${servicesDir}/ticket/server/server`); + +describe('ticket model TicketTracking', () => { + let ticketTrackingId; + + afterAll(async() => { + await app.models.TicketPackaging.destroyById(ticketTrackingId); + }); + + it('should save a ticketTraing as the quantity is greater than 0', async() => { + let result = await app.models.TicketPackaging.create({ticketFk: 1, quantity: 1, packagingFk: 1}); + + expect(result).toBeTruthy(); + ticketTrackingId = result.id; + }); + + it('should return an error as the quantity is 0', async() => { + let error; + try { + await app.models.TicketPackaging.create({ticketFk: 1, quantity: 0, packagingFk: 1}); + } catch (e) { + error = e; + } + + expect(error.message).toContain('Enter an integer different to zero'); + }); + + it('should return an error as the quantity isnt a number', async() => { + let error; + try { + await app.models.TicketPackaging.create({ticketFk: 1, quantity: 'random string', packagingFk: 1}); + } catch (e) { + error = e; + } + + expect(error.message).toContain('Enter an integer different to zero'); + }); +});