From 051f4c20f0d32bf9403050b3c35a3c1cf5b7fa54 Mon Sep 17 00:00:00 2001 From: shamoon <4887959+shamoon@users.noreply.github.com> Date: Mon, 18 Sep 2023 12:57:18 -0700 Subject: [PATCH] Maybe almost 100% test coverage --- ...ion-template-edit-dialog.component.spec.ts | 10 +++++ .../mail-rule-edit-dialog.component.spec.ts | 3 -- .../test_migration_consumption_templates.py | 43 +++++++++++++++++++ 3 files changed, 53 insertions(+), 3 deletions(-) create mode 100644 src/documents/tests/test_migration_consumption_templates.py diff --git a/src-ui/src/app/components/common/edit-dialog/consumption-template-edit-dialog/consumption-template-edit-dialog.component.spec.ts b/src-ui/src/app/components/common/edit-dialog/consumption-template-edit-dialog/consumption-template-edit-dialog.component.spec.ts index 8fee3fae5..f582c9e16 100644 --- a/src-ui/src/app/components/common/edit-dialog/consumption-template-edit-dialog/consumption-template-edit-dialog.component.spec.ts +++ b/src-ui/src/app/components/common/edit-dialog/consumption-template-edit-dialog/consumption-template-edit-dialog.component.spec.ts @@ -18,6 +18,7 @@ import { of } from 'rxjs' import { CorrespondentService } from 'src/app/services/rest/correspondent.service' import { DocumentTypeService } from 'src/app/services/rest/document-type.service' import { StoragePathService } from 'src/app/services/rest/storage-path.service' +import { MailRuleService } from 'src/app/services/rest/mail-rule.service' describe('ConsumptionTemplateEditDialogComponent', () => { let component: ConsumptionTemplateEditDialogComponent @@ -81,6 +82,15 @@ describe('ConsumptionTemplateEditDialogComponent', () => { }), }, }, + { + provide: MailRuleService, + useValue: { + listAll: () => + of({ + results: [], + }), + }, + }, ], imports: [ HttpClientTestingModule, diff --git a/src-ui/src/app/components/common/edit-dialog/mail-rule-edit-dialog/mail-rule-edit-dialog.component.spec.ts b/src-ui/src/app/components/common/edit-dialog/mail-rule-edit-dialog/mail-rule-edit-dialog.component.spec.ts index b2876c6ad..97854bd73 100644 --- a/src-ui/src/app/components/common/edit-dialog/mail-rule-edit-dialog/mail-rule-edit-dialog.component.spec.ts +++ b/src-ui/src/app/components/common/edit-dialog/mail-rule-edit-dialog/mail-rule-edit-dialog.component.spec.ts @@ -26,9 +26,6 @@ import { CheckComponent } from '../../input/check/check.component' describe('MailRuleEditDialogComponent', () => { let component: MailRuleEditDialogComponent let fixture: ComponentFixture - let accountService: MailAccountService - let correspondentService: CorrespondentService - let documentTypeService: DocumentTypeService beforeEach(async () => { TestBed.configureTestingModule({ diff --git a/src/documents/tests/test_migration_consumption_templates.py b/src/documents/tests/test_migration_consumption_templates.py new file mode 100644 index 000000000..3374530a2 --- /dev/null +++ b/src/documents/tests/test_migration_consumption_templates.py @@ -0,0 +1,43 @@ +from django.contrib.auth import get_user_model + +from documents.tests.utils import TestMigrations + + +class TestMigrateConsumptionTemplate(TestMigrations): + migrate_from = "1038_sharelink" + migrate_to = "1039_consumptiontemplate" + + def setUpBeforeMigration(self, apps): + User = get_user_model() + Group = apps.get_model("auth.Group") + self.Permission = apps.get_model("auth", "Permission") + self.user = User.objects.create(username="user1") + self.group = Group.objects.create(name="group1") + permission = self.Permission.objects.get(codename="add_document") + self.user.user_permissions.add(permission.id) + self.group.permissions.add(permission.id) + + def test_users_with_add_documents_get_add_consumptiontemplate(self): + permission = self.Permission.objects.get(codename="add_consumptiontemplate") + self.assertTrue(self.user.has_perm(f"documents.{permission.codename}")) + self.assertTrue(permission in self.group.permissions.all()) + + +class TestReverseMigrateConsumptionTemplate(TestMigrations): + migrate_from = "1039_consumptiontemplate" + migrate_to = "1038_sharelink" + + def setUpBeforeMigration(self, apps): + User = get_user_model() + Group = apps.get_model("auth.Group") + self.Permission = apps.get_model("auth", "Permission") + self.user = User.objects.create(username="user1") + self.group = Group.objects.create(name="group1") + permission = self.Permission.objects.get(codename="add_consumptiontemplate") + self.user.user_permissions.add(permission.id) + self.group.permissions.add(permission.id) + + def test_remove_consumptiontemplate_permissions(self): + permission = self.Permission.objects.get(codename="add_consumptiontemplate") + self.assertFalse(self.user.has_perm(f"documents.{permission.codename}")) + self.assertFalse(permission in self.group.permissions.all())