import { Injectable } from '@angular/core'; import { GCMockModule } from '@core/mocks/gc-module.mock'; import currencies from '@core/static-assets/currencies'; import languages from '@core/static-assets/languages'; import { APIAdminClient, ClientSettings, CurrencySetting, SelectedLangsFromApi } from '@core/typings/api/admin-client.typing'; import { ClientBrandingFromApi } from '@core/typings/branding.typing'; import { ProcessingTypes } from '@core/typings/payment.typing'; import { ClientSettingsService } from '@features/client-settings/client-settings.service'; import { BeforeEach, Spec, TestCase } from '@yourcause/test-decorators'; import { DescribeAngularService } from '@yourcause/test-decorators/angular'; import { expect } from 'chai'; import { ClientSettingsResources } from './client-settings.resources'; @Injectable({ providedIn: 'root' }) @DescribeAngularService(ClientSettingsService, { imports: [ GCMockModule ] }) export class ClientSettingsServiceSpec implements Spec { clientSettings: ClientSettings = { clientId: 1, paymentDesignations: true, specialHandling: true, allowExpeditedPayments: true, hasInternational: true, hasSSO: true, country: 'US', defaultTimezone: null, allowBudgetOverages: true, apEnabled: true, canConfigureWebservices: true, isTestClient: true, reserveFunds: true, allowExternalApis: true, isRootClient: false, allowExternalEmails: false, clientProcessingType: ProcessingTypes.Client, applicantTypesSupported: APIAdminClient.SupportedApplicantTypes.EmployeesAndNonprofits }; selectedLanguagesFromApi: SelectedLangsFromApi[] = [{ culture: 'cs-CZ', displayName: 'Czech', default: false }, { culture: 'de-DE', displayName: 'Deutsch', default: false }, { culture: 'el-GR', displayName: 'Greek', default: false }, { culture: 'en-GB', displayName: 'English (British)', default: false }, { culture: 'en-US', displayName: 'English', default: true }]; selectedCurrencies: CurrencySetting[] = [{ code: 'AUD', displayName: 'Australian Dollar', default: false }, { code: 'CAD', displayName: 'Canadian Dollar', default: false }, { code: 'EUR', displayName: 'Euro', default: false }, { code: 'USD', displayName: 'US Dollar', default: true }]; clientBranding: ClientBrandingFromApi = { logoName: '3f77a9af-5f36-4d11-9a26-fe6993b8ab98.jpg', logoUrl: 'https://grantsconnect-qa.imgix.net/management/47/images/3f77a9af-5f36-4d11-9a26-fe6993b8ab98.jpg', brandPrimary: '#e9511f', brandSecondary: '#9aeb97', brandUtility: '#57f3d6', name: 'YourCause Lori', subDomain: 'lori', loginBehavior: 2, hasImportedFromUAT: false, siteId: 1, clientColorSchemes: [] }; constructor ( private clientSettingResources: ClientSettingsResources ) { } @BeforeEach() mock (service: ClientSettingsService) { service['clientSettingsResources'] = this.clientSettingResources; this.clientSettingResources.getClientSettings = async () => { return this.clientSettings; }; this.clientSettingResources.getClientSettingsForApplicant = async () => { return this.clientSettings; }; this.clientSettingResources.getSelectedLanguages = async () => { return this.selectedLanguagesFromApi; }; this.clientSettingResources.getSelectedCurrencies = async () => { return this.selectedCurrencies; }; this.clientSettingResources.getBranding = async () => { return this.clientBranding; }; } @TestCase('should be able get and set langKeys') async getAllLangs (service: ClientSettingsService) { service.setAllLangs(); const langKeys = service.get('langKeys'); expect(langKeys.length).to.be.equal(languages.length); } @TestCase('should be able get and set language settings') async getLanguageSettings (service: ClientSettingsService) { await service.setLanguageSettings(); const selectedLangs = service.selectedLanguages; expect(selectedLangs.length).to.be.equal(this.selectedLanguagesFromApi.length); } @TestCase('should be able get and set defaultLanguage') async getDefaultLanguage (service: ClientSettingsService) { await service.setLanguageSettings(); const defaultLang = service.defaultLanguage; expect(defaultLang).to.be.equal('en-US'); } @TestCase('should be able get and set currencies') getAllCurrencies (service: ClientSettingsService) { service.setAllCurrencies(); expect(service.currencies.length).to.be.equal(currencies.length); } @TestCase('should be able get and set currency settings') async getCurrencySettings (service: ClientSettingsService) { await service.setCurrencySettings(); const selectedCurrencies = service.selectedCurrencies; expect(selectedCurrencies.length).to.be.equal(4); } @TestCase('should be able get and set defaultCurrency') async getDefaultCurrency (service: ClientSettingsService) { await service.setCurrencySettings(); const defaultCurrency = service.defaultCurrency; expect(defaultCurrency).to.be.equal('USD'); } @TestCase('should be able get and set clientSettings') async getClientSettings (service: ClientSettingsService) { await service.setClientSettings(); const clientSettings = service.clientSettings; expect(clientSettings.paymentDesignations).to.be.equal(true); expect(clientSettings.clientId).to.equal(1); expect(clientSettings.country).to.be.equal('US'); } @TestCase('should be able get and set clientSettings for applicant') async getClientSettingsForApplicant (service: ClientSettingsService) { await service.setClientSettingsForApplicant(1); const clientSettings = service.clientSettings; expect(clientSettings.paymentDesignations).to.be.equal(true); expect(clientSettings.country).to.be.equal('US'); } }