Skip to content

Commit

Permalink
Adjust and extend tests
Browse files Browse the repository at this point in the history
  • Loading branch information
carlobeltrame committed Mar 27, 2024
1 parent 81a5694 commit 21db621
Show file tree
Hide file tree
Showing 2 changed files with 100 additions and 5 deletions.
101 changes: 99 additions & 2 deletions api/tests/Api/Categories/CreateCategoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,10 +99,10 @@ public function testCreateCategoryCreatesNewColumnLayoutAsRootContentNode() {

$this->assertResponseStatusCodeSame(201);
$newestColumnLayout = $this->getEntityManager()->getRepository(ContentNode::class)
->findBy(['contentType' => static::$fixtures['contentTypeColumnLayout']], ['createTime' => 'DESC'])[0]
->findBy(['contentType' => static::$fixtures['contentTypeColumnLayout'], 'instanceName' => null], ['createTime' => 'DESC'], 1)[0]
;
$this->assertJsonContains(['_links' => [
'rootContentNode' => ['href' => '/content_node/column_layouts/'.$newestColumnLayout->getId()],
'rootContentNode' => ['href' => $this->getIriFor($newestColumnLayout)],
]]);
}

Expand Down Expand Up @@ -456,6 +456,102 @@ public function testCreateCategoryValidatesInvalidNumberingStyle() {
]);
}

public function testCreateCategoryFromCopySourceValidatesAccess() {
static::createClientWithCredentials(['email' => static::$fixtures['user8memberOnlyInCamp2']->getEmail()])->request(
'POST',
'/categories',
['json' => $this->getExampleWritePayload(
[
'camp' => $this->getIriFor('camp2'),
'copyCategorySource' => $this->getIriFor('category1'),
]
)]
);

// No Access on category1 -> BadRequest
$this->assertResponseStatusCodeSame(400);
}

public function testCreateCategoryFromCopySourceWithinSameCamp() {
static::createClientWithCredentials()->request(
'POST',
'/categories',
['json' => $this->getExampleWritePayload(
[
'camp' => $this->getIriFor('camp1'),
'copyCategorySource' => $this->getIriFor('category1'),
],
)]
);

// Category created
$this->assertResponseStatusCodeSame(201);
}

public function testCreateCategoryFromCopySourceAcrossCamp() {
static::createClientWithCredentials()->request(
'POST',
'/categories',
['json' => $this->getExampleWritePayload(
[
'camp' => $this->getIriFor('camp2'),
'copyCategorySource' => $this->getIriFor('category1'),
],
)]
);

// Category created
$this->assertResponseStatusCodeSame(201);
}

public function testCreateCategoryFromCopySourceActivityValidatesAccess() {
static::createClientWithCredentials(['email' => static::$fixtures['user8memberOnlyInCamp2']->getEmail()])->request(
'POST',
'/categories',
['json' => $this->getExampleWritePayload(
[
'camp' => $this->getIriFor('camp2'),
'copyCategorySource' => $this->getIriFor('activity1'),
]
)]
);

// No Access on activity1 -> BadRequest
$this->assertResponseStatusCodeSame(400);
}

public function testCreateCategoryFromCopySourceActivityWithinSameCamp() {
static::createClientWithCredentials()->request(
'POST',
'/categories',
['json' => $this->getExampleWritePayload(
[
'camp' => $this->getIriFor('camp1'),
'copyCategorySource' => $this->getIriFor('activity1'),
],
)]
);

// Category created
$this->assertResponseStatusCodeSame(201);
}

public function testCreateCategoryFromCopySourceActivityAcrossCamp() {
static::createClientWithCredentials()->request(
'POST',
'/categories',
['json' => $this->getExampleWritePayload(
[
'camp' => $this->getIriFor('camp2'),
'copyCategorySource' => $this->getIriFor('activity1'),
],
)]
);

// Category created
$this->assertResponseStatusCodeSame(201);
}

/**
* @throws RedirectionExceptionInterface
* @throws DecodingExceptionInterface
Expand Down Expand Up @@ -488,6 +584,7 @@ public function getExampleWritePayload($attributes = [], $except = []) {
Category::class,
Post::class,
array_merge([
'copyCategorySource' => null,
'camp' => $this->getIriFor('camp1'),
'preferredContentTypes' => [$this->getIriFor('contentTypeSafetyConcept')],
], $attributes),
Expand Down
4 changes: 1 addition & 3 deletions frontend/src/components/campAdmin/DialogCategoryCreate.vue
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,7 @@
<template #activator="{ on }">
<v-btn v-show="clipboardPermission === 'prompt'" v-on="on">
<v-icon left>mdi-information-outline</v-icon>
{{
$tc('components.campAdmin.dialogCategoryCreate.copyPasteCategory')
}}
{{ $tc('components.campAdmin.dialogCategoryCreate.copyPasteCategory') }}
</v-btn>
</template>
</CopyCategoryInfoDialog>
Expand Down

0 comments on commit 21db621

Please sign in to comment.