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 e644613
Show file tree
Hide file tree
Showing 3 changed files with 124 additions and 8 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
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,7 @@ components:
format: iri-reference
type: string
copyActivitySource:
description: 'Copy Contents from this Source-Activity.'
description: 'Copy contents from this source activity.'
example: /activities/1a2b3c4d
format: iri-reference
type:
Expand Down Expand Up @@ -762,7 +762,7 @@ components:
format: iri-reference
type: string
copyActivitySource:
description: 'Copy Contents from this Source-Activity.'
description: 'Copy contents from this source activity.'
example: /activities/1a2b3c4d
format: iri-reference
type:
Expand Down Expand Up @@ -1201,7 +1201,7 @@ components:
format: iri-reference
type: string
copyActivitySource:
description: 'Copy Contents from this Source-Activity.'
description: 'Copy contents from this source activity.'
example: /activities/1a2b3c4d
format: iri-reference
type:
Expand Down Expand Up @@ -5998,6 +5998,13 @@ components:
maxLength: 8
pattern: '^(#[0-9a-zA-Z]{6})$'
type: string
copyCategorySource:
description: 'Copy contents from this source category or activity.'
example: /categories/1a2b3c4d
format: iri-reference
type:
- 'null'
- string
name:
description: 'The full name of the category.'
example: Lagersport
Expand Down Expand Up @@ -6383,6 +6390,13 @@ components:
maxLength: 8
pattern: '^(#[0-9a-zA-Z]{6})$'
type: string
copyCategorySource:
description: 'Copy contents from this source category or activity.'
example: /categories/1a2b3c4d
format: iri-reference
type:
- 'null'
- string
name:
description: 'The full name of the category.'
example: Lagersport
Expand Down Expand Up @@ -6755,6 +6769,13 @@ components:
maxLength: 8
pattern: '^(#[0-9a-zA-Z]{6})$'
type: string
copyCategorySource:
description: 'Copy contents from this source category or activity.'
example: /categories/1a2b3c4d
format: iri-reference
type:
- 'null'
- string
name:
description: 'The full name of the category.'
example: Lagersport
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 e644613

Please sign in to comment.