-
Notifications
You must be signed in to change notification settings - Fork 467
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
### Proposed Changes * I'm opening the possibility of passing a publishDate through the GQL API * Additionally, I saw an opportunity to improve our passing the request into a method that uses it. Previously, it was being grabbed by the current thread. We should avoid using the Current Thread to pass around the request, as it is the source of memory leaks
- Loading branch information
1 parent
7503306
commit 82ddbb0
Showing
20 changed files
with
629 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,132 @@ | ||
Feature: Reusable Functions and Helpers | ||
|
||
Scenario: Define reusable functions | ||
|
||
## General error free validation | ||
* def validateNoErrors = | ||
""" | ||
function (response) { | ||
const errors = response.errors; | ||
if (errors) { | ||
return errors; | ||
} | ||
return []; | ||
} | ||
""" | ||
|
||
## Builds a payload for creating a new content version | ||
* def buildContentRequestPayload = | ||
""" | ||
function(contentType, title, publishDate, expiresOn, identifier) { | ||
let payload = { | ||
"contentlets": [ | ||
{ | ||
"contentType": contentType, | ||
"title": title, | ||
"host":"8a7d5e23-da1e-420a-b4f0-471e7da8ea2d" | ||
} | ||
] | ||
}; | ||
if (publishDate) payload.contentlets[0].publishDate = publishDate; | ||
if (expiresOn) payload.contentlets[0].expiresOn = expiresOn; | ||
if (identifier) payload.contentlets[0].identifier = identifier; | ||
return payload; | ||
} | ||
""" | ||
## Extracts all errors from a response | ||
* def extractErrors = | ||
""" | ||
function(response) { | ||
let errors = []; | ||
let results = response.entity.results; | ||
if (results && results.length > 0) { | ||
for (let i = 0; i < results.length; i++) { | ||
let result = results[i]; | ||
// Handle both nested error messages and direct error messages | ||
for (let key in result) { | ||
if (result[key] && result[key].errorMessage) { | ||
errors.push(result[key].errorMessage); | ||
} | ||
} | ||
} | ||
} | ||
return errors; | ||
} | ||
""" | ||
|
||
## Extracts all contentlets from a response | ||
* def extractContentlets = | ||
""" | ||
function(response) { | ||
let containers = response.entity.containers; | ||
let allContentlets = []; | ||
for (let key in containers) { | ||
if (containers[key].contentlets) { | ||
for (let contentletKey in containers[key].contentlets) { | ||
allContentlets = allContentlets.concat(containers[key].contentlets[contentletKey]); | ||
} | ||
} | ||
} | ||
return allContentlets; | ||
} | ||
""" | ||
|
||
## Generates a random suffix for test data | ||
* def testSuffix = | ||
""" | ||
function() { | ||
if (!karate.get('testSuffix')) { | ||
let prefix = '__' + Math.floor(Math.random() * 100000); | ||
karate.set('testSuffix', prefix); | ||
} | ||
return karate.get('testSuffix'); | ||
} | ||
""" | ||
|
||
## Extracts a specific object from a JSON array by UUID | ||
* def getContentletByUUID = | ||
""" | ||
function(jsonArray, uuid) { | ||
for (let i = 0; i < jsonArray.length; i++) { | ||
let keys = Object.keys(jsonArray[i]); | ||
if (keys.includes(uuid)) { | ||
return jsonArray[i][uuid]; | ||
} | ||
} | ||
return null; // Return null if not found | ||
} | ||
""" | ||
|
||
## Builds a payload for creating a new GraphQL request | ||
* def buildGraphQLRequestPayload = | ||
""" | ||
function(pageUri, publishDate) { | ||
if (!pageUri.startsWith('/')) { | ||
pageUri = '/' + pageUri; | ||
} | ||
var query = 'query Page { page(url: "' + pageUri + '"'; | ||
if (publishDate) { | ||
query += ' publishDate: "' + publishDate + '"'; | ||
} | ||
query += ') { containers { containerContentlets { contentlets { title } } } } }'; | ||
return { query: query }; | ||
} | ||
""" | ||
|
||
## Extracts all contentlet titles from a GraphQL response | ||
* def contentletsFromGraphQlResponse = | ||
""" | ||
function(response) { | ||
let containers = response.data.page.containers; | ||
let allTitles = []; | ||
containers.forEach(container => { | ||
container.containerContentlets.forEach(cc => { | ||
cc.contentlets.forEach(contentlet => { | ||
allTitles.push(contentlet.title); | ||
}); | ||
}); | ||
}); | ||
return allTitles; | ||
} | ||
""" | ||
## |
24 changes: 24 additions & 0 deletions
24
test-karate/src/test/java/graphql/ftm/newContainer.feature
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
Feature: Create a Container | ||
Background: | ||
* def containerNameVariable = 'MyContainer' + Math.floor(Math.random() * 100000) | ||
|
||
Scenario: Create a content type and expect 200 OK | ||
Given url baseUrl + '/api/v1/containers' | ||
And headers commonHeaders | ||
And request | ||
""" | ||
{ | ||
"title":"#(containerNameVariable)", | ||
"friendlyName":"My test container.", | ||
"maxContentlets":10, | ||
"notes":"Notes", | ||
"containerStructures":[ | ||
{ | ||
"structureId":"#(contentTypeId)", | ||
"code":"$!{dotContentMap.title}" | ||
} | ||
] | ||
} | ||
""" | ||
When method POST | ||
Then status 200 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
Feature: Create an instance of a new Content Type and expect 200 OK | ||
Background: | ||
|
||
Scenario: Create an instance of a new Content Type and expect 200 OK | ||
|
||
# Params are expected as arguments to the feature file | ||
* def contentTypeId = __arg.contentTypeId | ||
* def title = __arg.title | ||
* def publishDate = __arg.publishDate | ||
* def expiresOn = __arg.expiresOn | ||
|
||
Given url baseUrl + '/api/v1/workflow/actions/default/fire/PUBLISH?indexPolicy=WAIT_FOR' | ||
And headers commonHeaders | ||
|
||
* def requestPayload = buildContentRequestPayload (contentTypeId, title, publishDate, expiresOn) | ||
And request requestPayload | ||
|
||
When method POST | ||
Then status 200 | ||
* def errors = call extractErrors response | ||
* match errors == [] |
Oops, something went wrong.