Skip to content

Commit

Permalink
Use @ for all references in Gherkin features + explicit name for ever…
Browse files Browse the repository at this point in the history
…ything

Signed-off-by: Geoffrey Huck <geoffrey@geot.fr>
  • Loading branch information
GeoffreyHuck committed Apr 19, 2023
1 parent c9687fb commit 26ffdc1
Show file tree
Hide file tree
Showing 10 changed files with 118 additions and 134 deletions.
17 changes: 5 additions & 12 deletions app/api/threads/list_threads.feature
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Feature: List threads
Background:
And there are the following groups:
| name | parent | members |
| group | parent | members |
| @Consortium | | @ConsortiumMember |
| @A_University | @Consortium | @A_UniversityMember,@A_UniversityManagerCanWatch |
| @B_University | @Consortium | @B_UniversityMember |
Expand All @@ -11,7 +11,7 @@ Feature: List threads
| @B_Class | @B_Section | |
| @OtherGroup | | @OtherGroupMember |
And @A_UniversityManagerCanWatch is a manager of the group @A_University and can watch its members
And there are the following item tasks:
And there are the following tasks:
| item |
| @B_SectionMember2_CanViewInfo |
| @B_SectionMember2_CanViewContent1 |
Expand All @@ -38,12 +38,6 @@ Feature: List threads
| @B_SectionMember2_CanViewContent1 | @B_SectionMember2 | content | |
| @B_SectionMember2_CanViewContent2 | @B_SectionMember2 | content | |
| @B_SectionMember2_CanViewContentWithDescendants | @B_SectionMember2 | content_with_descendants | |
| @B_UniversityMember_HasValidated1 | @B_UniversityMember | | |
| @B_UniversityMember_HasValidated2 | @B_UniversityMember | | |
| @B_UniversityMember_HasValidated3 | @B_UniversityMember | | |
| @B_UniversityMember_HasValidated4 | @B_UniversityMember | | |
| @B_UniversityMember_HasValidated5 | @B_UniversityMember | | |
| @B_UniversityMember_HasValidated6 | @B_UniversityMember | | |
| @B_UniversityMember_HasNotValidated | @B_UniversityMember | | answer |
| @B_UniversityMember_CanWatchAnswer1 | @B_UniversityMember | | answer |
| @B_UniversityMember_CanWatchAnswer2 | @B_UniversityMember | | answer |
Expand Down Expand Up @@ -85,7 +79,7 @@ Feature: List threads
Given I am @LaboratoryManagerCanWatch
And I am a manager of the group @Laboratory and can watch its members
And there are the following users:
| login | first_name | last_name |
| user | first_name | last_name |
| @LaboratoryMember_WithApprovedAccessPersonalInfo | FirstName_Approved | LastName_Approved |
| @LaboratoryMember_WithoutApprovedAccessPersonalInfo | FirstName_NotApproved | LastName_NotApproved |
And @LaboratoryMember_WithApprovedAccessPersonalInfo is a member of the group @Laboratory who has approved access to his personal info
Expand Down Expand Up @@ -148,15 +142,14 @@ Feature: List threads
Scenario: Should get the threads whose the participant is a descendant of the watched_group_id
Given I am @A_UniversityManagerCanWatch
When I send a GET request to "/threads?watched_group_id=@A_University"
And it should be a JSON array with 2 entries
And the response at $[*].participant.id should be:
| @A_UniversityMember |
| @A_ClassMember |
| @A_ClassMember |

Scenario: Should get the threads whose the participant is equal to the watched_group_id
Given I am @A_UniversityManagerCanWatch
When I send a GET request to "/threads?watched_group_id=@A_ClassMember"
And it should be a JSON array with 1 entries
And the response should be a JSON array with 1 entries
And the response at $[0].participant.id should be "@A_ClassMember"

Scenario: Should return only the threads in which the participant is the current user and the item is visible when is_mine=1
Expand Down
16 changes: 8 additions & 8 deletions app/api/threads/list_threads.robustness.feature
Original file line number Diff line number Diff line change
@@ -1,33 +1,33 @@
Feature: List threads - robustness
Scenario: Should be logged in
Given there is a group Classroom referenced by @Classroom
Given there is a group @Classroom
When I send a GET request to "/threads?watched_group_id=@Classroom"
Then the response code should be 401
And the response error message should contain "No access token provided"

Scenario: watched_group_id should be an integer
Given I am John
Given I am @John
When I send a GET request to "/threads?watched_group_id=aaa"
Then the response code should be 400
And the response error message should contain "Wrong value for watched_group_id (should be int64)"

Scenario: watched_group_id should be given because the alternative is not implemented yet
Given I am John
Given I am @John
When I send a GET request to "/threads"
Then the response code should be 400
And the response error message should contain "Not implemented yet: watchedGroupID must be given"

Scenario: The user should be a manager of watched_group_id group
Given I am John
And there is a group Classroom referenced by @Classroom
Given I am @John
And there is a group @Classroom
When I send a GET request to "/threads?watched_group_id=@Classroom"
Then the response code should be 403
And the response error message should contain "No rights to watch for watched_group_id"

Scenario: The user should be able to watch the watched_group_id group
Given I am John
And there is a group Classroom referenced by @Classroom
And I am a manager of the group Classroom
Given I am @John
And there is a group @Classroom
And I am a manager of the group @Classroom
When I send a GET request to "/threads?watched_group_id=@Classroom"
Then the response code should be 403
And the response error message should contain "No rights to watch for watched_group_id"
1 change: 1 addition & 0 deletions app/api/threads/update_thread.feature
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,7 @@ Feature: Update thread
| 2009 | waiting_for_participant | 12 | In chapter |
| 2010 | waiting_for_participant | 11 | In chapter |

Scenario: Participant who can request help on region can request help on class
Scenario: Participant who can request help on region can request help on class
Given I am the user with id "3"
And there is no thread with "item_id=270,participant_id=3"
Expand Down
5 changes: 2 additions & 3 deletions testhelpers/feature_context.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func FeatureContext(s *godog.Suite) {
s.Step(`^(@\w+) is a manager of the group (@\w+) and can watch its members$`, ctx.UserIsAManagerOfTheGroupAndCanWatchItsMembers)
s.Step(`^I am a manager of the group (@\w+) and can watch its members$`, ctx.IAmAManagerOfTheGroupAndCanWatchItsMembers)
s.Step(`^the group (@\w+) is a descendant of the group (@\w+)$`, ctx.theGroupIsADescendantOfTheGroup)
s.Step(`^there are the following item tasks:$`, ctx.ThereAreTheFollowingItemTasks)
s.Step(`^there are the following tasks:$`, ctx.ThereAreTheFollowingTasks)
s.Step(`^there are the following item permissions:$`, ctx.ThereAreTheFollowingItemPermissions)
s.Step(`^I can watch the group (@\w+)$`, ctx.ICanWatchGroup)
s.Step(`^I can watch the participant with id "([^"]*)"$`, ctx.ICanWatchGroupWithID)
Expand Down Expand Up @@ -77,10 +77,9 @@ func FeatureContext(s *godog.Suite) {
s.Step(`^the response should be "([^"]*)"$`, ctx.TheResponseShouldBe)
s.Step(`^the response error message should contain "(.*)"$`, ctx.TheResponseErrorMessageShouldContain)

s.Step(`^it should be a JSON array with (\d+) entr(ies|y)$`, ctx.ItShouldBeAJSONArrayWithEntries)
s.Step(`^the response should be a JSON array with (\d+) entr(ies|y)$`, ctx.ItShouldBeAJSONArrayWithEntries)
s.Step(`^the response at ([^ ]+) should be "([^"]+)"$`, ctx.TheResponseAtShouldBeTheValue)
s.Step("^the response at ([^ ]+) should be:$", ctx.TheResponseAtShouldBe)
s.Step(`^the response should match the following JSONPath:$`, ctx.TheResponseAtShouldBe)

s.Step(`^the table "([^"]*)" should be:$`, ctx.TableShouldBe)
s.Step(`^the table "([^"]*)" should be empty$`, ctx.TableShouldBeEmpty)
Expand Down
80 changes: 42 additions & 38 deletions testhelpers/steps_app_language.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,10 @@ func (ctx *TestContext) getUserKey(fields map[string]string) string {
func (ctx *TestContext) addUser(fields map[string]string) {
dbFields := make(map[string]interface{})
for key, value := range fields {
if key == "user" {
key = "login"
}

switch {
case strings.HasSuffix(key, "_id"):
dbFields[key] = ctx.getReference(value)
Expand Down Expand Up @@ -330,7 +334,7 @@ func (ctx *TestContext) IAm(name string) error {
func (ctx *TestContext) ThereIsAUser(name string) error {
return ctx.ThereIsAUserWith(getParameterString(map[string]string{
"group_id": name,
"login": name,
"user": name,
}))
}

Expand All @@ -339,14 +343,14 @@ func (ctx *TestContext) ThereIsAUserWith(parameters string) error {
user := ctx.getParameterMap(parameters)

if _, ok := user["group_id"]; !ok {
user["group_id"] = user["login"]
user["group_id"] = user["user"]
}

ctx.addUser(user)

return ctx.ThereIsAGroupWith(getParameterString(map[string]string{
"id": user["group_id"],
"name": user["login"],
"name": user["user"],
"type": "User",
}))
}
Expand All @@ -356,13 +360,13 @@ func (ctx *TestContext) ThereAreTheFollowingGroups(groups *messages.PickleStepAr
for i := 1; i < len(groups.Rows); i++ {
group := ctx.getRowMap(i, groups)

err := ctx.ThereIsAGroup(group["name"])
err := ctx.ThereIsAGroup(group["group"])
if err != nil {
return err
}

if _, ok := group["parent"]; ok {
err = ctx.GroupIsAChildOfTheGroup(group["name"], group["parent"])
err = ctx.GroupIsAChildOfTheGroup(group["group"], group["parent"])
if err != nil {
return err
}
Expand All @@ -382,7 +386,7 @@ func (ctx *TestContext) ThereAreTheFollowingGroups(groups *messages.PickleStepAr
return err
}

err = ctx.GroupIsAChildOfTheGroup(member, group["name"])
err = ctx.GroupIsAChildOfTheGroup(member, group["group"])
if err != nil {
return err
}
Expand Down Expand Up @@ -419,7 +423,7 @@ func (ctx *TestContext) ThereAreTheFollowingUsers(users *messages.PickleStepArgu
return err
}

err = ctx.ThereIsAGroup(user["login"])
err = ctx.ThereIsAGroup(user["user"])
if err != nil {
return err
}
Expand All @@ -429,10 +433,10 @@ func (ctx *TestContext) ThereAreTheFollowingUsers(users *messages.PickleStepArgu
}

// ThereIsAGroup creates a new group.
func (ctx *TestContext) ThereIsAGroup(groupName string) error {
func (ctx *TestContext) ThereIsAGroup(group string) error {
return ctx.ThereIsAGroupWith(getParameterString(map[string]string{
"id": groupName,
"name": groupName,
"id": group,
"name": group,
}))
}

Expand Down Expand Up @@ -479,31 +483,31 @@ func (ctx *TestContext) IAmAManagerOfTheGroupWithID(group string) error {
}

// IAmAManagerOfTheGroup sets the user as a manager of a group with an id.
func (ctx *TestContext) IAmAManagerOfTheGroup(groupName string) error {
func (ctx *TestContext) IAmAManagerOfTheGroup(group string) error {
return ctx.UserIsAManagerOfTheGroupWith(getParameterString(map[string]string{
"id": groupName,
"id": group,
"user_id": ctx.user,
"name": groupName,
"name": group,
"can_watch_members": "false",
}))
}

// IAmAManagerOfTheGroupAndCanWatchItsMembers sets the user as a manager of a group with can_watch permission.
func (ctx *TestContext) IAmAManagerOfTheGroupAndCanWatchItsMembers(groupName string) error {
func (ctx *TestContext) IAmAManagerOfTheGroupAndCanWatchItsMembers(group string) error {
return ctx.UserIsAManagerOfTheGroupWith(getParameterString(map[string]string{
"id": groupName,
"id": group,
"user_id": ctx.user,
"name": groupName,
"name": group,
"can_watch_members": "true",
}))
}

// UserIsAManagerOfTheGroupAndCanWatchItsMembers sets the user as a manager of a group with can_watch permission.
func (ctx *TestContext) UserIsAManagerOfTheGroupAndCanWatchItsMembers(userName, groupName string) error {
func (ctx *TestContext) UserIsAManagerOfTheGroupAndCanWatchItsMembers(user, group string) error {
return ctx.UserIsAManagerOfTheGroupWith(getParameterString(map[string]string{
"id": groupName,
"user_id": userName,
"name": groupName,
"id": group,
"user_id": user,
"name": group,
"can_watch_members": "true",
}))
}
Expand Down Expand Up @@ -538,12 +542,12 @@ func (ctx *TestContext) ICanWatchGroupWithID(group string) error {
}))
}

// ThereAreTheFollowingItemTasks defines item tasks.
func (ctx *TestContext) ThereAreTheFollowingItemTasks(itemTasks *messages.PickleStepArgument_PickleTable) error {
for i := 1; i < len(itemTasks.Rows); i++ {
item := ctx.getRowMap(i, itemTasks)
// ThereAreTheFollowingTasks defines item tasks.
func (ctx *TestContext) ThereAreTheFollowingTasks(tasks *messages.PickleStepArgument_PickleTable) error {
for i := 1; i < len(tasks.Rows); i++ {
task := ctx.getRowMap(i, tasks)

ctx.addItem(item["item"])
ctx.addItem(task["item"])
}

return nil
Expand Down Expand Up @@ -603,48 +607,48 @@ func (ctx *TestContext) IAmAMemberOfTheGroupWithID(group string) error {
}

// GroupIsAChildOfTheGroup puts a group as a child of another group.
func (ctx *TestContext) GroupIsAChildOfTheGroup(childGroupName, parentGroupName string) error {
func (ctx *TestContext) GroupIsAChildOfTheGroup(childGroup, parentGroup string) error {
err := ctx.ThereIsAGroupWith(getParameterString(map[string]string{
"id": childGroupName,
"name": childGroupName,
"id": childGroup,
"name": childGroup,
}))
if err != nil {
return err
}

err = ctx.ThereIsAGroupWith(getParameterString(map[string]string{
"id": parentGroupName,
"name": parentGroupName,
"id": parentGroup,
"name": parentGroup,
}))
if err != nil {
return err
}

ctx.IsAMemberOfTheGroup(childGroupName, parentGroupName)
ctx.IsAMemberOfTheGroup(childGroup, parentGroup)

return nil
}

// UserIsAMemberOfTheGroup puts a user in a group.
func (ctx *TestContext) UserIsAMemberOfTheGroup(userName, groupName string) error {
func (ctx *TestContext) UserIsAMemberOfTheGroup(user, group string) error {
err := ctx.ThereIsAUserWith(getParameterString(map[string]string{
"group_id": userName,
"login": userName,
"group_id": user,
"user": user,
}))
if err != nil {
return err
}

return ctx.GroupIsAChildOfTheGroup(userName, groupName)
return ctx.GroupIsAChildOfTheGroup(user, group)
}

// UserIsAMemberOfTheGroupWhoHasApprovedAccessToHisPersonalInfo puts a user in a group with approved access to his personnel info.
func (ctx *TestContext) UserIsAMemberOfTheGroupWhoHasApprovedAccessToHisPersonalInfo(userName, groupName string) error {
err := ctx.UserIsAMemberOfTheGroup(userName, groupName)
func (ctx *TestContext) UserIsAMemberOfTheGroupWhoHasApprovedAccessToHisPersonalInfo(user, group string) error {
err := ctx.UserIsAMemberOfTheGroup(user, group)
if err != nil {
return err
}
ctx.addPersonalInfoViewApprovedFor(userName, groupName)
ctx.addPersonalInfoViewApprovedFor(user, group)

return nil
}
Expand Down
9 changes: 7 additions & 2 deletions testhelpers/steps_db.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ const (
deleted
)

const (
UserGroupID = "group_id"
UserLogin = "login"
)

func (ctx *TestContext) DBHasTable(table string, data *messages.PickleStepArgument_PickleTable) error { // nolint
db := ctx.db()

Expand Down Expand Up @@ -110,11 +115,11 @@ func (ctx *TestContext) DBHasUsers(data *messages.PickleStepArgument_PickleTable
groupIDColumnNumber := -1
loginColumnNumber := -1
for number, cell := range head {
if cell.Value == "group_id" {
if cell.Value == UserGroupID {
groupIDColumnNumber = number
continue
}
if cell.Value == "login" {
if cell.Value == UserLogin {
loginColumnNumber = number
continue
}
Expand Down
3 changes: 3 additions & 0 deletions testhelpers/steps_misc.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"fmt"
"net/http"
"regexp"
"strconv"
"strings"
"time"

Expand All @@ -29,6 +30,8 @@ import (

func (ctx *TestContext) IAmUserWithID(userID int64) error { //nolint
ctx.userID = userID
ctx.user = strconv.FormatInt(userID, 10)

db, err := database.Open(ctx.db())
if err != nil {
return err
Expand Down
Loading

0 comments on commit 26ffdc1

Please sign in to comment.