Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
it('should set consentGiven according to the state of the provided consent', () => {
component.consent = { consentState: ANONYMOUS_CONSENT_STATUS.GIVEN };
component.isAnonymousConsentsEnabled = true;
component.ngOnInit();
expect(component.consentGiven).toEqual(true);
});
});
describe('rejectAll', () => {
const mockConsent: AnonymousConsent[] = [
{
templateCode: mockTemplates[0].id,
consentState: ANONYMOUS_CONSENT_STATUS.GIVEN,
},
{
templateCode: mockTemplates[1].id,
consentState: ANONYMOUS_CONSENT_STATUS.GIVEN,
},
];
describe('when a required consent is present', () => {
it('should skip it', () => {
anonymousConsentsConfig.anonymousConsents.requiredConsents = [
mockTemplates[0].id,
];
spyOn(component, 'closeModal').and.stub();
spyOn(component['subscriptions'], 'add').and.callThrough();
spyOn(anonymousConsentsService, 'isConsentGiven').and.returnValues(
true,
true
);
spyOn(anonymousConsentsService, 'withdrawConsent').and.stub();
component.templates$ = of(mockTemplates);
ngOnInit(): void {
if (this.isAnonymousConsentsEnabled && this.consent) {
this.consentGiven = Boolean(
this.consent.consentState === ANONYMOUS_CONSENT_STATUS.GIVEN
);
} else {
if (this.consentTemplate && this.consentTemplate.currentConsent) {
if (this.consentTemplate.currentConsent.consentWithdrawnDate) {
this.consentGiven = false;
} else if (this.consentTemplate.currentConsent.consentGivenDate) {
this.consentGiven = true;
}
}
}
}
it('should call anonymousConsentsService.isConsentGiven', () => {
spyOn(anonymousConsentService, 'isConsentGiven').and.stub();
const mockConsent: AnonymousConsent = {
consentState: ANONYMOUS_CONSENT_STATUS.GIVEN,
};
component.isConsentGiven(mockConsent);
expect(anonymousConsentService.isConsentGiven).toHaveBeenCalledWith(
mockConsent
);
});
});
describe('rejectAll', () => {
const mockConsent: AnonymousConsent[] = [
{
templateCode: mockTemplates[0].id,
consentState: ANONYMOUS_CONSENT_STATUS.GIVEN,
},
{
templateCode: mockTemplates[1].id,
consentState: ANONYMOUS_CONSENT_STATUS.GIVEN,
},
];
describe('when a required consent is present', () => {
it('should skip it', () => {
anonymousConsentsConfig.anonymousConsents.requiredConsents = [
mockTemplates[0].id,
];
spyOn(component, 'closeModal').and.stub();
spyOn(component['subscriptions'], 'add').and.callThrough();
spyOn(anonymousConsentsService, 'isConsentGiven').and.returnValues(
true,
true