Skip to content

Commit

Permalink
Add integration tests for systemic question creation #248
Browse files Browse the repository at this point in the history
  • Loading branch information
robertfausk committed Jan 2, 2025
1 parent 84cda78 commit 03d5b2b
Show file tree
Hide file tree
Showing 2 changed files with 151 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ final class SystemicQuestionCreateRequest
{
#[Assert\NotBlank]
#[Assert\NotNull]
#[Assert\Length(['min' => 3, 'max' => 4000, 'normalizer' => 'trim'])]
#[Assert\Length(['min' => 5, 'max' => 4000, 'normalizer' => 'trim'])]
#[Assert\Type(['type' => 'string'])]
public string $question;

Expand Down
150 changes: 150 additions & 0 deletions web/tests/Integration/features/systemic_question_create.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
Feature: Testing systemic question resource

Background:
Given the following clients exists:
| email |
| client@gmx.de |
| gamer@gmx.de |
| main@gmx.de |
Given the following users exists:
| email | roles | client |
| karl@gmx.de | | client@gmx.de |
| karl@gamer.de | | gamer@gmx.de |
| admin@gmx.de | ROLE_ADMIN | client@gmx.de |
| superadmin@gmx.de | ROLE_SUPER_ADMIN | main@gmx.de |
Given the following systemic questions exists:
| question | client |
| Is Gewalt good for you? | client@gmx.de |
| Is Drogen good for you? | client@gmx.de |
| Is RPG good for you? | gamer@gmx.de |

@api @apiSystemicQuestionCreate
Scenario: I can request /api/systemic_questions/create as a not authenticated user and an auth error will occur
When I send an api platform "POST" request to "/api/systemic_questions/create" with parameters:
| key | value |
| question | PowderBlue |
| client | clientIri<client@gmx.de> |
Then the response should be in JSON
And the response status code should be 401
# And print last JSON response
And the JSON nodes should be equal to:
| code | 401 |

@api @apiSystemicQuestionCreate
Scenario: I can request /api/systemic_questions/create as authenticated user and will get access denied
Given I am authenticated against api as "[email protected]"
When I send an api platform "POST" request to "/api/systemic_questions/create" with parameters:
| key | value |
| question | PowderBlue |
| client | clientIri<client@gmx.de> |
Then the response should be in JSON
And the response status code should be 403
# And print last JSON response
And the JSON nodes should be equal to:
| hydra:description | Access Denied. |

@api @apiSystemicQuestionCreate
Scenario: I can request /api/systemic_questions/create as an admin for another client and will get access denied
Given I am authenticated against api as "[email protected]"
When I send an api platform "POST" request to "/api/systemic_questions/create" with parameters:
| key | value |
| question | Religion |
| client | clientIri<gamer@gmx.de> |
Then the response should be in JSON
# And print last JSON response
And the response status code should be 400
And the JSON nodes should be equal to:
| hydra:title | An error occurred |

@api @apiSystemicQuestionCreate
Scenario: I can request /api/systemic_questions/create as an admin and will get access denied
Given I am authenticated against api as "[email protected]"
When I send an api platform "POST" request to "/api/systemic_questions/create" with parameters:
| key | value |
| question | Religion |
| client | clientIri<client@gmx.de> |
Then the response should be in JSON
And the response status code should be 200
# And print last JSON response
And the JSON nodes should be equal to:
| question | Religion |

@api @apiSystemicQuestionCreate
Scenario: I can request /api/systemic_questions/create as an superadmin and will create a new systemic question
Given I am authenticated against api as "[email protected]"
When I send an api platform "POST" request to "/api/systemic_questions/create" with parameters:
| key | value |
| question | Religion |
| client | clientIri<client@gmx.de> |
Then the response should be in JSON
And the response status code should be 200
# And print last JSON response
And the JSON nodes should be equal to:
| question | Religion |

@api @apiSystemicQuestionCreate
Scenario: I can request /api/systemic_questions/create as an superadmin with invalid color and will get a validation error
Given I am authenticated against api as "[email protected]"
When I send an api platform "POST" request to "/api/systemic_questions/create" with parameters:
| key | value |
| question | ab |
| client | clientIri<client@gmx.de> |
Then the response should be in JSON
# And print last JSON response
And the response status code should be 422
And the JSON nodes should be equal to:
| violations[0].propertyPath | question |
| violations[0].message | Diese Zeichenkette ist zu kurz. Sie sollte mindestens 5 Zeichen haben. |

@api @apiSystemicQuestionCreate
Scenario: I can request /api/systemic_questions/create as an superadmin with empty color and name and will get a validation error
Given I am authenticated against api as "[email protected]"
When I send an api platform "POST" request to "/api/systemic_questions/create" with parameters:
| key | value |
| question | |
| client | clientIri<client@gmx.de> |
Then the response should be in JSON
# And print last JSON response
And the response status code should be 422
And the JSON nodes should be equal to:
| violations[0].propertyPath | question |
| violations[0].message | Dieser Wert sollte nicht leer sein. |

@api @apiSystemicQuestionCreate
Scenario: I can request /api/systemic_questions/create as an superadmin with nulled color and name and will get a validation error
Given I am authenticated against api as "[email protected]"
When I send an api platform "POST" request to "/api/systemic_questions/create" with parameters:
| key | value |
| question | <null> |
| client | clientIri<client@gmx.de> |
Then the response should be in JSON
# And print last JSON response
And the response status code should be 400
And the JSON nodes should be equal to:
| hydra:description | The input data is misformatted. |

@api @apiSystemicQuestionCreate
Scenario: I can request /api/systemic_questions/create as an superadmin with unset color and name and will get a validation error
Given I am authenticated against api as "[email protected]"
When I send an api platform "POST" request to "/api/systemic_questions/create" with parameters:
| key | value |
| client | clientIri<client@gmx.de> |
Then the response should be in JSON
# And print last JSON response
And the response status code should be 422
And the JSON nodes should be equal to:
| violations[0].propertyPath | question |
| violations[0].message | Dieser Wert sollte nicht leer sein. |

@api @apiSystemicQuestionCreate
Scenario: I can request /api/systemic_questions/create as an superadmin with already existing name and will get a validation error
Given I am authenticated against api as "[email protected]"
When I send an api platform "POST" request to "/api/systemic_questions/create" with parameters:
| key | value |
| question | Drogen |
| client | clientIri<gamer@gmx.de> |
Then the response should be in JSON
# And print last JSON response
And the response status code should be 200
And the JSON nodes should be equal to:
| question | Drogen |

0 comments on commit 03d5b2b

Please sign in to comment.