Skip to content

Commit

Permalink
Fix the exclude param in list resource_list.feature.
Browse files Browse the repository at this point in the history
  • Loading branch information
NofarVered committed Jul 21, 2023
1 parent 1bc4ca8 commit c75b253
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 9 deletions.
3 changes: 2 additions & 1 deletion app/models/resource.rb
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,8 @@ def search account: nil, kind: nil, owner: nil, offset: nil, limit: nil, search:
exclude = exclude.split(',')
exclude.each do |item|
# scope is exclude when the resource id is like the item
scope = scope.exclude(Sequel.like(:resource_id, "%#{item}%"))
# client who gives exclude param should write the prefix id just after the account
scope = scope.exclude(Sequel.like(:resource_id, "#{account}"+":#{item}%"))
end
end

Expand Down
33 changes: 25 additions & 8 deletions cucumber/api/features/resource_list.feature
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,10 @@ Feature: List resources with various types of filtering
cucumber:user:alice successfully listed resources with parameters: {:account=>"cucumber", :kind=>"test-resource", :count=>"true"}
"""

################
# exclude param
################

@acceptance
Scenario: The resource list is excluded for all directories.
Given I create a new resource called "target-resource-0"
Expand All @@ -235,7 +239,7 @@ Feature: List resources with various types of filtering
@acceptance
Scenario: The resource list is excluded for a specific directory.
Given I create a new resource called "target-resource-0"
When I successfully GET "/resources/cucumber/test-resource?exclude=target-resource-0"
When I successfully GET "/resources/cucumber/test-resource?exclude=test-resource:target-resource-0"
Then the resource list should not include the newest resource

@acceptance
Expand All @@ -249,7 +253,7 @@ Feature: List resources with various types of filtering
Given I create a new resource called "target-resource-0"
And I create a new resource called "target-resource-1"
And I create a new resource called "target-resource-2"
When I successfully GET "/resources/cucumber/test-resource?exclude=target-resource-0,target-resource-1,target-resource-2"
When I successfully GET "/resources/cucumber/test-resource?exclude=test-resource:target-resource-0,test-resource:target-resource-1,test-resource:target-resource-2"
Then I receive 3 resources

@acceptance
Expand All @@ -265,7 +269,7 @@ Feature: List resources with various types of filtering
And I create a new resource called "target-resource-1"
And I create a new resource called "target-resource-2"
# resources created, either in background and this scenario, are under test-resource directory
When I successfully GET "/resources/cucumber/test-resource?exclude=test-resource,target-resource-0"
When I successfully GET "/resources/cucumber/test-resource?exclude=test-resource,test-resource:target-resource-0"
Then the result is empty

@acceptance
Expand All @@ -276,20 +280,33 @@ Feature: List resources with various types of filtering

@acceptance
Scenario: The resource list is excluded for special-character directory.
Given I create a new resource called "target-resource-./:;<=>?_`{|}]'()*+,-@#"
When I successfully GET "/resources/cucumber/test-resource?exclude=resource-./:;<=>?_`{|}]'()*+,-@#"
Given I create a new resource called "resource-./:;<=>?_`{|}]'()*+,-@#"
When I successfully GET "/resources/cucumber/test-resource?exclude=test-resource:resource-./:;<=>?_`{|}]'()*+,-@#"
Then the resource list should not include the newest resource

@acceptance
Scenario: The resource list is excluded and search a resource.
Given I create a new resource called "target-resource-0"
And I create a new resource called "find-me"
When I successfully GET "/resources/cucumber/test-resource?exclude=target-resource-0&search=find-me"
When I successfully GET "/resources/cucumber/test-resource?exclude=test-resource:target-resource-0&search=find-me"
Then the resource list should include the newest resource

@acceptance
Scenario: The resource list is excluded and search a resource.
Given I create a new resource called "target-resource-0"
And I create a new resource called "find-me"
When I successfully GET "/resources/cucumber/test-resource?exclude=target-resource-0&search=target-resource-0"
Then the result is empty
When I successfully GET "/resources/cucumber/test-resource?exclude=test-resource:target-resource-0&search=test-resource:target-resource-0"
Then the result is empty

@acceptance
Scenario: The resource list is excluded and search a resource.
Given I create a new resource called "target-resource-0"
And I create a new resource called "find-me"
When I successfully GET "/resources/cucumber/test-resource?exclude=test-resource:target-resource-0&search=test-resource:target-resource-0"
Then the result is empty

@acceptance
Scenario: The resource list is not excluded for sub string input of a resource.
Given I create a new resource called "target-resource-0"
When I successfully GET "/resources/cucumber/test-resource?exclude=resource"
Then the resource list should be include the all resources

0 comments on commit c75b253

Please sign in to comment.