From 3dbe599cb380a2686c8d3c6c2c3a0cb3f5ed4416 Mon Sep 17 00:00:00 2001 From: Faruk AYDIN Date: Fri, 8 Nov 2024 12:55:37 +0100 Subject: [PATCH] test: Implement initial tests for SamlAuthProvider model --- .../saml-auth-provider.ee.test.js.snap | 72 +++++++++++++++++++ .../src/models/saml-auth-provider.ee.test.js | 48 +++++++++++++ 2 files changed, 120 insertions(+) create mode 100644 packages/backend/src/models/__snapshots__/saml-auth-provider.ee.test.js.snap create mode 100644 packages/backend/src/models/saml-auth-provider.ee.test.js diff --git a/packages/backend/src/models/__snapshots__/saml-auth-provider.ee.test.js.snap b/packages/backend/src/models/__snapshots__/saml-auth-provider.ee.test.js.snap new file mode 100644 index 00000000..7050feca --- /dev/null +++ b/packages/backend/src/models/__snapshots__/saml-auth-provider.ee.test.js.snap @@ -0,0 +1,72 @@ +// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html + +exports[`SamlAuthProvider model > jsonSchema should have the correct schema 1`] = ` +{ + "properties": { + "active": { + "type": "boolean", + }, + "certificate": { + "minLength": 1, + "type": "string", + }, + "defaultRoleId": { + "format": "uuid", + "type": "string", + }, + "emailAttributeName": { + "minLength": 1, + "type": "string", + }, + "entryPoint": { + "minLength": 1, + "type": "string", + }, + "firstnameAttributeName": { + "minLength": 1, + "type": "string", + }, + "id": { + "format": "uuid", + "type": "string", + }, + "issuer": { + "minLength": 1, + "type": "string", + }, + "name": { + "minLength": 1, + "type": "string", + }, + "roleAttributeName": { + "minLength": 1, + "type": "string", + }, + "signatureAlgorithm": { + "enum": [ + "sha1", + "sha256", + "sha512", + ], + "type": "string", + }, + "surnameAttributeName": { + "minLength": 1, + "type": "string", + }, + }, + "required": [ + "name", + "certificate", + "signatureAlgorithm", + "entryPoint", + "issuer", + "firstnameAttributeName", + "surnameAttributeName", + "emailAttributeName", + "roleAttributeName", + "defaultRoleId", + ], + "type": "object", +} +`; diff --git a/packages/backend/src/models/saml-auth-provider.ee.test.js b/packages/backend/src/models/saml-auth-provider.ee.test.js new file mode 100644 index 00000000..3ea21268 --- /dev/null +++ b/packages/backend/src/models/saml-auth-provider.ee.test.js @@ -0,0 +1,48 @@ +import { describe, it, expect } from 'vitest'; +import SamlAuthProvider from '../models/saml-auth-provider.ee'; +import SamlAuthProvidersRoleMapping from '../models/saml-auth-providers-role-mapping.ee'; +import Identity from './identity.ee'; +import Base from './base'; + +describe('SamlAuthProvider model', () => { + it('tableName should return correct name', () => { + expect(SamlAuthProvider.tableName).toBe('saml_auth_providers'); + }); + + it('jsonSchema should have the correct schema', () => { + expect(SamlAuthProvider.jsonSchema).toMatchSnapshot(); + }); + + it('relationMappings should return correct associations', () => { + const relationMappings = SamlAuthProvider.relationMappings(); + + const expectedRelations = { + identities: { + relation: Base.HasOneRelation, + modelClass: Identity, + join: { + from: 'identities.provider_id', + to: 'saml_auth_providers.id', + }, + }, + samlAuthProvidersRoleMappings: { + relation: Base.HasManyRelation, + modelClass: SamlAuthProvidersRoleMapping, + join: { + from: 'saml_auth_providers.id', + to: 'saml_auth_providers_role_mappings.saml_auth_provider_id', + }, + }, + }; + + expect(relationMappings).toStrictEqual(expectedRelations); + }); + + it('virtualAttributes should return correct attributes', () => { + const virtualAttributes = SamlAuthProvider.virtualAttributes; + + const expectedAttributes = ['loginUrl', 'remoteLogoutUrl']; + + expect(virtualAttributes).toStrictEqual(expectedAttributes); + }); +});