Skip to content

Commit

Permalink
feat: integration tests
Browse files Browse the repository at this point in the history
  • Loading branch information
fiftin committed Mar 3, 2024
1 parent 2513768 commit 06cf907
Show file tree
Hide file tree
Showing 13 changed files with 49 additions and 86 deletions.
3 changes: 2 additions & 1 deletion .dredd/hooks/capabilities.go
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,7 @@ func alterRequestBody(t *trans.Transaction) {
bodyFieldProcessor("integration_id", integration.ID, &request)
}
if integrationextractor != nil {
//bodyFieldProcessor("integration_id", integrationextractor.IntegrationID, &request)
bodyFieldProcessor("extractor_id", integrationextractor.ID, &request)
}
if integrationextractvalue != nil {
Expand All @@ -246,7 +247,7 @@ func alterRequestBody(t *trans.Transaction) {
// Inject object ID to body for PUT requests
if strings.ToLower(t.Request.Method) == "put" {

putRequestPathRE := regexp.MustCompile(`/api/(?:project/\d+/)?\w+/(\d+)/?(?:integrations/\d+/|integrations/\d+/extractor/\d+)?(?:integration/\d+/extractor/\d+/matcher/\d+)?(?:integration/\d+/extractor/\d+/value/\d+)?$`)
putRequestPathRE := regexp.MustCompile(`/api/(?:project/\d+/)?\w+/(\d+)/?(?:integrations/\d+/|integrations/\d+/extractors/\d+)?(?:integrations/\d+/extractors/\d+/matchers/\d+)?(?:integrations/\d+/extractors/\d+/values/\d+)?$`)
m := putRequestPathRE.FindStringSubmatch(t.FullPath)
if len(m) > 0 {
objectID, err := strconv.Atoi(m[1])
Expand Down
72 changes: 17 additions & 55 deletions .dredd/hooks/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,61 +79,23 @@ func main() {
transaction.Request.Body = "{ \"user_id\": " + strconv.Itoa(userPathTestUser.ID) + ",\"role\": \"owner\"}"
})

h.Before("project > /api/project/{project_id}/integrations > get all integrations > 200 > application/json", func(t *trans.Transaction) {
addCapabilities([]string{"repository", "inventory", "environment", "template", "integration"})
})

h.Before("project > /api/project/{project_id}/integrations/{integration_id} > Get Integration > 200 > application/json", func(t *trans.Transaction) {
addCapabilities([]string{"repository", "inventory", "environment", "template", "integration"})
})

h.Before("integration > /api/project/{project_id}/integrations/{integration_id}/extractors > Get Integration Extractors > 200 > application/json", func(t *trans.Transaction) {
addCapabilities([]string{"repository", "inventory", "environment", "template", "integration", "integrationextractor"})
})

h.Before("integration > /api/project/{project_id}/integrations/{integration_id}/extractors > Add Integration Extractor > 204 > application/json", func(t *trans.Transaction) {
addCapabilities([]string{"repository", "inventory", "environment", "template", "integration"})
})

h.Before("integration > /api/project/{project_id}/integrations/{integration_id}/extractor/{extractor_id} > Updates Integration extractor > 204 > application/json", func(t *trans.Transaction) {
addCapabilities([]string{"repository", "inventory", "environment", "template", "integration", "integrationextractor"})
})

h.Before("integration > /api/project/{project_id}/integrations/{integration_id}/extractor/{extractor_id} > Removes integration extractor > 204 > application/json", func(t *trans.Transaction) {
addCapabilities([]string{"repository", "inventory", "environment", "template", "integration", "integrationextractor"})
})

h.Before("integration > /api/project/{project_id}/integrations/{integration_id}/extractor/{extractor_id}/values > Get Integration Extracted Values linked to integration extractor > 200 > application/json", func(t *trans.Transaction) {
addCapabilities([]string{"repository", "inventory", "environment", "template", "integration", "integrationextractor", "integrationextractvalue"})
})

h.Before("integration > /api/project/{project_id}/integrations/{integration_id}/extractor/{extractor_id}/values > Add Integration Extracted Value > 204 > application/json", func(t *trans.Transaction) {
addCapabilities([]string{"repository", "inventory", "environment", "template", "integration", "integrationextractor", "integrationextractvalue"})
})

h.Before("integration > /api/project/{project_id}/integrations/{integration_id}/extractor/{extractor_id}/value/{extractvalue_id} > Removes integration extract value > 204 > application/json", func(t *trans.Transaction) {
addCapabilities([]string{"repository", "inventory", "environment", "template", "integration", "integrationextractor", "integrationextractvalue"})
})

h.Before("integration > /api/project/{project_id}/integrations/{integration_id}/extractor/{extractor_id}/values > Add Integration Extracted Value > 204 > application/json", func(t *trans.Transaction) {
addCapabilities([]string{"repository", "inventory", "environment", "template", "integration", "integrationextractor"})
})

h.Before("integration > /api/project/{project_id}/integrations/{integration_id}/extractor/{extractor_id}/value/{extractvalue_id} > Updates Integration ExtractValue > 204 > application/json", func(t *trans.Transaction) {
addCapabilities([]string{"repository", "inventory", "environment", "template", "integration", "integrationextractor", "integrationmatcher"})
})

h.Before("integration > /api/project/{project_id}/integrations/{integration_id}/extractor/{extractor_id}/matchers > Get Integration Matcher linked to integration extractor > 200 > application/json", func(t *trans.Transaction) {
addCapabilities([]string{"repository", "inventory", "environment", "template", "integration", "integrationextractor"})
})

h.Before("integration > /api/project/{project_id}/integrations/{integration_id}/extractor/{extractor_id}/matchers > Add Integration Matcher > 204 > application/json", func(t *trans.Transaction) {
addCapabilities([]string{"repository", "inventory", "environment", "template", "integration", "integrationextractor"})
})

h.Before("integration > /api/project/{project_id}/integrations/{integration_id}/extractor/{extractor_id}/matcher/{matcher_id} > Updates Integration Matcher > 204 > application/json", func(t *trans.Transaction) {
addCapabilities([]string{"repository", "inventory", "environment", "template", "integration", "integrationextractor", "integrationmatcher"})
})
h.Before("project > /api/project/{project_id}/integrations > get all integrations > 200 > application/json", capabilityWrapper("integration"))
h.Before("project > /api/project/{project_id}/integrations/{integration_id} > Get Integration > 200 > application/json", capabilityWrapper("integration"))
h.Before("project > /api/project/{project_id}/integrations/{integration_id} > Update Integration > 204 > application/json", capabilityWrapper("integration"))
h.Before("project > /api/project/{project_id}/integrations/{integration_id} > Remove integration > 204 > application/json", capabilityWrapper("integration"))

h.Before("integration > /api/project/{project_id}/integrations/{integration_id}/extractors > Get Integration Extractors > 200 > application/json", capabilityWrapper("integrationextractor"))
h.Before("integration > /api/project/{project_id}/integrations/{integration_id}/extractors > Add Integration Extractor > 204 > application/json", capabilityWrapper("integration"))
h.Before("integration > /api/project/{project_id}/integrations/{integration_id}/extractors/{extractor_id} > Updates Integration extractor > 204 > application/json", capabilityWrapper("integrationextractor"))
h.Before("integration > /api/project/{project_id}/integrations/{integration_id}/extractors/{extractor_id} > Removes integration extractor > 204 > application/json", capabilityWrapper("integrationextractor"))
h.Before("integration > /api/project/{project_id}/integrations/{integration_id}/extractors/{extractor_id}/values > Get Integration Extracted Values linked to integration extractor > 200 > application/json", capabilityWrapper("integrationextractvalue"))
h.Before("integration > /api/project/{project_id}/integrations/{integration_id}/extractors/{extractor_id}/values > Add Integration Extracted Value > 204 > application/json", capabilityWrapper("integrationextractvalue"))
h.Before("integration > /api/project/{project_id}/integrations/{integration_id}/extractors/{extractor_id}/values/{extractvalue_id} > Removes integration extract value > 204 > application/json", capabilityWrapper("integrationextractvalue"))
h.Before("integration > /api/project/{project_id}/integrations/{integration_id}/extractors/{extractor_id}/values > Add Integration Extracted Value > 204 > application/json", capabilityWrapper("integrationextractor"))
h.Before("integration > /api/project/{project_id}/integrations/{integration_id}/extractors/{extractor_id}/values/{extractvalue_id} > Updates Integration ExtractValue > 204 > application/json", capabilityWrapper("integrationmatcher"))
h.Before("integration > /api/project/{project_id}/integrations/{integration_id}/extractors/{extractor_id}/matchers > Get Integration Matcher linked to integration extractor > 200 > application/json", capabilityWrapper("integrationextractor"))
h.Before("integration > /api/project/{project_id}/integrations/{integration_id}/extractors/{extractor_id}/matchers > Add Integration Matcher > 204 > application/json", capabilityWrapper("integrationextractor"))
h.Before("integration > /api/project/{project_id}/integrations/{integration_id}/extractors/{extractor_id}/matchers/{matcher_id} > Updates Integration Matcher > 204 > application/json", capabilityWrapper("integrationmatcher"))

h.Before("project > /api/project/{project_id}/keys/{key_id} > Updates access key > 204 > application/json", capabilityWrapper("access_key"))
h.Before("project > /api/project/{project_id}/keys/{key_id} > Removes access key > 204 > application/json", capabilityWrapper("access_key"))
Expand Down
10 changes: 5 additions & 5 deletions api-docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1553,7 +1553,7 @@ paths:
responses:
204:
description: Integration Extractor Created
/project/{project_id}/integrations/{integration_id}/extractor/{extractor_id}:
/project/{project_id}/integrations/{integration_id}/extractors/{extractor_id}:
parameters:
- $ref: "#/parameters/project_id"
- $ref: "#/parameters/integration_id"
Expand All @@ -1578,7 +1578,7 @@ paths:
responses:
204:
description: integration extractor removed
/project/{project_id}/integrations/{integration_id}/extractor/{extractor_id}/values:
/project/{project_id}/integrations/{integration_id}/extractors/{extractor_id}/values:
parameters:
- $ref: "#/parameters/project_id"
- $ref: "#/parameters/integration_id"
Expand Down Expand Up @@ -1609,7 +1609,7 @@ paths:
description: Integration Extract Value Created
400:
description: Bad Integration Extract Value params
/project/{project_id}/integrations/{integration_id}/extractor/{extractor_id}/value/{extractvalue_id}:
/project/{project_id}/integrations/{integration_id}/extractors/{extractor_id}/values/{extractvalue_id}:
parameters:
- $ref: "#/parameters/project_id"
- $ref: "#/parameters/integration_id"
Expand Down Expand Up @@ -1637,7 +1637,7 @@ paths:
responses:
204:
description: integration extract value removed
/project/{project_id}/integrations/{integration_id}/extractor/{extractor_id}/matchers:
/project/{project_id}/integrations/{integration_id}/extractors/{extractor_id}/matchers:
parameters:
- $ref: "#/parameters/project_id"
- $ref: "#/parameters/integration_id"
Expand Down Expand Up @@ -1668,7 +1668,7 @@ paths:
description: Integration Matcher Created
400:
description: Bad Integration Matcher params
/project/{project_id}/integrations/{integration_id}/extractor/{extractor_id}/matcher/{matcher_id}:
/project/{project_id}/integrations/{integration_id}/extractors/{extractor_id}/matchers/{matcher_id}:
parameters:
- $ref: "#/parameters/project_id"
- $ref: "#/parameters/integration_id"
Expand Down
18 changes: 9 additions & 9 deletions api/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ func Route() *mux.Router {
projectIntegrationsAPI.HandleFunc("/{integration_id}/extractors", projects.GetIntegrationExtractors).Methods("GET")
projectIntegrationsAPI.HandleFunc("/{integration_id}/extractors", projects.AddIntegrationExtractor).Methods("POST")

projectIntegrationExtractorAPI := projectIntegrationsAPI.PathPrefix("/{integration_id}/extractor").Subrouter()
projectIntegrationExtractorAPI := projectIntegrationsAPI.PathPrefix("/{integration_id}/extractors").Subrouter()
projectIntegrationExtractorAPI.Use(projects.IntegrationExtractorMiddleware)

projectIntegrationExtractorAPI.HandleFunc("/{extractor_id}", projects.GetIntegrationExtractor).Methods("GET", "HEAD")
Expand All @@ -299,15 +299,15 @@ func Route() *mux.Router {
projectIntegrationExtractorAPI.HandleFunc("/{extractor_id}/values", projects.GetIntegrationExtractValues).Methods("GET", "HEAD")
projectIntegrationExtractorAPI.HandleFunc("/{extractor_id}/values", projects.AddIntegrationExtractValue).Methods("POST")

projectIntegrationExtractorAPI.HandleFunc("/{extractor_id}/matcher/{matcher_id}", projects.GetIntegrationMatcher).Methods("GET", "HEAD")
projectIntegrationExtractorAPI.HandleFunc("/{extractor_id}/matcher/{matcher_id}", projects.UpdateIntegrationMatcher).Methods("PUT")
projectIntegrationExtractorAPI.HandleFunc("/{extractor_id}/matcher/{matcher_id}", projects.DeleteIntegrationMatcher).Methods("DELETE")
projectIntegrationExtractorAPI.HandleFunc("/{extractor_id}/matcher/{matcher_id}/refs", projects.GetIntegrationMatcherRefs).Methods("GET", "HEAD")
projectIntegrationExtractorAPI.HandleFunc("/{extractor_id}/matchers/{matcher_id}", projects.GetIntegrationMatcher).Methods("GET", "HEAD")
projectIntegrationExtractorAPI.HandleFunc("/{extractor_id}/matchers/{matcher_id}", projects.UpdateIntegrationMatcher).Methods("PUT")
projectIntegrationExtractorAPI.HandleFunc("/{extractor_id}/matchers/{matcher_id}", projects.DeleteIntegrationMatcher).Methods("DELETE")
projectIntegrationExtractorAPI.HandleFunc("/{extractor_id}/matchers/{matcher_id}/refs", projects.GetIntegrationMatcherRefs).Methods("GET", "HEAD")

projectIntegrationExtractorAPI.HandleFunc("/{extractor_id}/value/{value_id}", projects.GetIntegrationExtractValue).Methods("GET", "HEAD")
projectIntegrationExtractorAPI.HandleFunc("/{extractor_id}/value/{value_id}", projects.UpdateIntegrationExtractValue).Methods("PUT")
projectIntegrationExtractorAPI.HandleFunc("/{extractor_id}/value/{value_id}", projects.DeleteIntegrationExtractValue).Methods("DELETE")
projectIntegrationExtractorAPI.HandleFunc("/{extractor_id}/value/{value_id}/refs", projects.GetIntegrationExtractValueRefs).Methods("GET")
projectIntegrationExtractorAPI.HandleFunc("/{extractor_id}/values/{value_id}", projects.GetIntegrationExtractValue).Methods("GET", "HEAD")
projectIntegrationExtractorAPI.HandleFunc("/{extractor_id}/values/{value_id}", projects.UpdateIntegrationExtractValue).Methods("PUT")
projectIntegrationExtractorAPI.HandleFunc("/{extractor_id}/values/{value_id}", projects.DeleteIntegrationExtractValue).Methods("DELETE")
projectIntegrationExtractorAPI.HandleFunc("/{extractor_id}/values/{value_id}/refs", projects.GetIntegrationExtractValueRefs).Methods("GET")

if os.Getenv("DEBUG") == "1" {
defer debugPrintRoutes(r)
Expand Down
2 changes: 1 addition & 1 deletion db/Integration.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
type IntegrationAuthMethod string

const (
IntegrationAuthNone = "none"
IntegrationAuthNone = ""
IntegrationAuthToken = "token"
IntegrationAuthHmac = "hmac"
)
Expand Down
6 changes: 3 additions & 3 deletions db/sql/integration.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func (d *SqlDb) CreateIntegration(integration db.Integration) (newIntegration db
"id",
"insert into project__integration "+
"(project_id, name, template_id, auth_method, auth_secret_id, auth_header) values "+
"(?, ?, ?)",
"(?, ?, ?, ?, ?, ?)",
integration.ProjectID,
integration.Name,
integration.TemplateID,
Expand Down Expand Up @@ -319,7 +319,7 @@ func (d *SqlDb) UpdateIntegrationExtractValue(integrationExtractValue db.Integra
}

_, err = d.exec(
"update project__integration_extract_value set value_source=?, body_data_type=?, key=?, variable=?, name=? where id=?",
"update project__integration_extract_value set value_source=?, body_data_type=?, `key`=?, `variable`=?, `name`=? where `id`=?",
integrationExtractValue.ValueSource,
integrationExtractValue.BodyDataType,
integrationExtractValue.Key,
Expand Down Expand Up @@ -418,7 +418,7 @@ func (d *SqlDb) UpdateIntegrationMatcher(integrationMatcher db.IntegrationMatche
}

_, err = d.exec(
"update project__integration_matcher set match_type=?, method=?, body_data_type=?, key=?, value=?, name=? where id=?",
"update project__integration_matcher set match_type=?, `method`=?, body_data_type=?, `key`=?, `value`=?, `name`=? where `id`=?",
integrationMatcher.MatchType,
integrationMatcher.Method,
integrationMatcher.BodyDataType,
Expand Down
4 changes: 2 additions & 2 deletions web/src/components/IntegrationExtractValueForm.vue
Original file line number Diff line number Diff line change
Expand Up @@ -117,10 +117,10 @@ export default {
},
methods: {
getItemsUrl() {
return `/api/project/${this.projectId}/integrations/${this.integrationId}/extractor/${this.extractorId}/values`;
return `/api/project/${this.projectId}/integrations/${this.integrationId}/extractors/${this.extractorId}/values`;
},
getSingleItemUrl() {
return `/api/project/${this.projectId}/integrations/${this.integrationId}/extractor/${this.extractorId}/value/${this.itemId}`;
return `/api/project/${this.projectId}/integrations/${this.integrationId}/extractors/${this.extractorId}/values/${this.itemId}`;
},
},
};
Expand Down
2 changes: 1 addition & 1 deletion web/src/components/IntegrationExtractorForm.vue
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export default {
return `/api/project/${this.projectId}/integrations/${this.integrationId}/extractors`;
},
getSingleItemUrl() {
return `/api/project/${this.projectId}/integrations/${this.integrationId}/extractor/${this.itemId}`;
return `/api/project/${this.projectId}/integrations/${this.integrationId}/extractors/${this.itemId}`;
},
},
};
Expand Down
4 changes: 2 additions & 2 deletions web/src/components/IntegrationMatcherForm.vue
Original file line number Diff line number Diff line change
Expand Up @@ -138,10 +138,10 @@ export default {
},
methods: {
getItemsUrl() {
return `/api/project/${this.projectId}/integrations/${this.integrationId}/extractor/${this.extractorId}/matchers`;
return `/api/project/${this.projectId}/integrations/${this.integrationId}/extractors/${this.extractorId}/matchers`;
},
getSingleItemUrl() {
return `/api/project/${this.projectId}/integrations/${this.integrationId}/extractor/${this.extractorId}/matcher/${this.itemId}`;
return `/api/project/${this.projectId}/integrations/${this.integrationId}/extractors/${this.extractorId}/matchers/${this.itemId}`;
},
},
};
Expand Down
4 changes: 2 additions & 2 deletions web/src/views/project/IntegrationExtractValue.vue
Original file line number Diff line number Diff line change
Expand Up @@ -158,10 +158,10 @@ export default {
}];
},
getItemsUrl() {
return `/api/project/${this.projectId}/integrations/${this.integrationId}/extractor/${this.extractorId}/values`;
return `/api/project/${this.projectId}/integrations/${this.integrationId}/extractors/${this.extractorId}/values`;
},
getSingleItemUrl() {
return `/api/project/${this.projectId}/integrations/${this.integrationId}/extractor/${this.extractorId}/value/${this.itemId}`;
return `/api/project/${this.projectId}/integrations/${this.integrationId}/extractors/${this.extractorId}/values/${this.itemId}`;
},
getEventName() {
return 'w-integration-extract-value';
Expand Down
4 changes: 2 additions & 2 deletions web/src/views/project/IntegrationExtractorCrumb.vue
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export default {
this.extractor = (await axios({
method: 'get',
url: `/api/project/${this.projectId}/integrations/${this.integrationId}/extractor/${this.extractorId}`,
url: `/api/project/${this.projectId}/integrations/${this.integrationId}/extractors/${this.extractorId}`,
responseType: 'json',
})).data;
},
Expand Down Expand Up @@ -80,7 +80,7 @@ export default {
return `/api/project/${this.projectId}/integrations/${this.integrationId}/extractors`;
},
getSingleItemUrl() {
return `/api/project/${this.projectId}/integrations/${this.integrationId}/extractor/${this.extractorId}`;
return `/api/project/${this.projectId}/integrations/${this.integrationId}/extractors/${this.extractorId}`;
},
getEventName() {
return 'w-integration-matcher';
Expand Down
2 changes: 1 addition & 1 deletion web/src/views/project/IntegrationExtractors.vue
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ export default {
return `/api/project/${this.projectId}/integrations/${this.integrationId}/extractors`;
},
getSingleItemUrl() {
return `/api/project/${this.projectId}/integrations/${this.integrationId}/extractor/${this.itemId}`;
return `/api/project/${this.projectId}/integrations/${this.integrationId}/extractors/${this.itemId}`;
},
getEventName() {
return 'w-integration-extractor';
Expand Down
Loading

0 comments on commit 06cf907

Please sign in to comment.