From e8f149a22b99011a1f6b7d36f034c1e2e656ebd5 Mon Sep 17 00:00:00 2001 From: manelcecs Date: Fri, 15 Nov 2024 09:59:33 +0100 Subject: [PATCH] Add tests --- tests/utils/types.spec.ts | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 tests/utils/types.spec.ts diff --git a/tests/utils/types.spec.ts b/tests/utils/types.spec.ts new file mode 100644 index 00000000..05dd0dc3 --- /dev/null +++ b/tests/utils/types.spec.ts @@ -0,0 +1,34 @@ +import { getTableColumns } from '../../src/util/types'; +import ContextProvider from '../testContext'; + +const context = ContextProvider.Instance; + +describe("Test 'getTableColumns' function", () => { + it('should return the columns of a table', () => { + const columns = getTableColumns(context.models.emergency); + + expect(columns).toBeDefined(); + expect(columns).toBeInstanceOf(Array); + const expectedColumns = [ + 'id', + 'name', + 'date', + 'restricted', + 'active', + 'createdAt', + 'updatedAt', + 'description', + 'glideId', + 'levelThree', + ]; + expectedColumns.forEach((column) => { + expect(columns).toContain(column); + }); + }); + it('should return an empty array if the table has no columns', () => { + const columns = getTableColumns({ _internals: { fields: {} } }); + expect(columns).toBeDefined(); + expect(columns).toBeInstanceOf(Array); + expect(columns).toHaveLength(0); + }); +});