Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#23603 : Allow users to write code when creating a file - PR2 #24267

Merged
merged 15 commits into from
Mar 10, 2023
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 28 additions & 1 deletion dotCMS/src/curl-test/Content Resource.postman_collection.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"info": {
"_postman_id": "64a156b5-40b4-46ce-8bab-6083e910e48a",
"_postman_id": "50e22041-5236-42d7-8d37-b9a39f0457e3",
"name": "Content Resource",
"description": "Content Resource test",
"schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json",
Expand Down Expand Up @@ -1763,6 +1763,15 @@
"type": "text"
}
],
"body": {
"mode": "raw",
"raw": "{}",
"options": {
"raw": {
"language": "json"
}
}
},
"url": {
"raw": "{{serverURL}}/api/v1/workflow/actions/default/fire/UNPUBLISH?inode={{fileInode}}&identifier={{fileId}}",
"host": [
Expand Down Expand Up @@ -1835,6 +1844,15 @@
"type": "text"
}
],
"body": {
"mode": "raw",
"raw": "{}",
"options": {
"raw": {
"language": "json"
}
}
},
"url": {
"raw": "{{serverURL}}/api/v1/workflow/actions/default/fire/ARCHIVE?inode={{fileInode}}&identifier={{fileId}}",
"host": [
Expand Down Expand Up @@ -1907,6 +1925,15 @@
"type": "text"
}
],
"body": {
"mode": "raw",
"raw": "{}",
"options": {
"raw": {
"language": "json"
}
}
},
"url": {
"raw": "{{serverURL}}/api/v1/workflow/actions/default/fire/DELETE?inode={{fileInode}}&identifier={{fileId}}",
"host": [
Expand Down
299 changes: 291 additions & 8 deletions dotCMS/src/curl-test/TempAPI.postman_collection.json
Original file line number Diff line number Diff line change
@@ -1,26 +1,279 @@
{
"info": {
"_postman_id": "1faea77b-c035-4129-a215-3608487d19b3",
"_postman_id": "b65639a1-cec6-4b6c-b8b6-ab483db33b5b",
"name": "TempAPI",
"description": "Verifies that the Temp File API is working as expected. It allows users to create temporary files in the dotCMS assets folder.",
"schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json",
"_exporter_id": "11174695"
"_exporter_id": "5403727"
},
"item": [
{
"name": "Temp File As Plain Text",
"item": [
{
"name": "Create Temp File",
"event": [
{
"listen": "prerequest",
"script": {
"exec": [
"let randomNumber = Math.floor(Math.random() * 100);",
"pm.collectionVariables.set(\"tempFileName\", randomNumber + \"-test-temp-file.txt\");"
],
"type": "text/javascript"
}
},
{
"listen": "test",
"script": {
"exec": [
"pm.test(\"Test Temporary File creation HTTP Status must be successful\", function() {",
" pm.response.to.have.status(200);",
"});",
"",
"pm.collectionVariables.set(\"tempFileId\", pm.response.json().tempFiles[0].id);"
],
"type": "text/javascript"
}
}
],
"request": {
"auth": {
"type": "basic",
"basic": [
{
"key": "username",
"value": "[email protected]",
"type": "string"
},
{
"key": "password",
"value": "admin",
"type": "string"
}
]
},
"method": "PUT",
"header": [
{
"key": "Origin",
"value": "localhost",
"type": "text"
}
],
"body": {
"mode": "raw",
"raw": "{\n \"fileName\": \"{{tempFileName}}\",\n \"fileContent\": \"This is the content of the Temporary File.\"\n}",
"options": {
"raw": {
"language": "json"
}
}
},
"url": {
"raw": "{{serverURL}}/api/v1/temp/id/new",
"host": [
"{{serverURL}}"
],
"path": [
"api",
"v1",
"temp",
"id",
"new"
]
}
},
"response": []
},
{
"name": "Update Existing Temp File Content",
"event": [
{
"listen": "test",
"script": {
"exec": [
"pm.test(\"Test Temporary File update HTTP Status must be successful\", function() {",
" pm.response.to.have.status(200);",
"});",
"",
"pm.test(\"Temporary File ID must be the same\", function() {",
" let tempFileId = pm.collectionVariables.get(\"tempFileId\");",
" pm.expect(pm.response.json().tempFiles[0].id).to.eql(tempFileId, \"An error occurred when checking the temp file ID\");",
"});"
],
"type": "text/javascript"
}
}
],
"request": {
"auth": {
"type": "basic",
"basic": [
{
"key": "username",
"value": "[email protected]",
"type": "string"
},
{
"key": "password",
"value": "admin",
"type": "string"
}
]
},
"method": "PUT",
"header": [
{
"key": "Origin",
"value": "localhost",
"type": "text"
}
],
"body": {
"mode": "raw",
"raw": "{\n \"fileName\": \"{{tempFileName}}\",\n \"fileContent\": \"This is the new content of the Temporary File.\"\n}",
"options": {
"raw": {
"language": "json"
}
}
},
"url": {
"raw": "{{serverURL}}/api/v1/temp/id/{{tempFileId}}",
"host": [
"{{serverURL}}"
],
"path": [
"api",
"v1",
"temp",
"id",
"{{tempFileId}}"
]
}
},
"response": []
},
{
"name": "Update Non-Existent Temp File",
"event": [
{
"listen": "test",
"script": {
"exec": [
"pm.test(\"Non-Existing Test Temporary File creation HTTP Status must be successful\", function() {",
" pm.response.to.have.status(200);",
"});",
"",
"pm.test(\"New Temporary File ID must NOT match the previous one\", function() {",
" let tempFileId = pm.collectionVariables.get(\"tempFileId\");",
" pm.expect(pm.response.json().tempFiles[0].id).to.not.eql(tempFileId, \"An error occurred when checking different temp file IDs\");",
"});"
],
"type": "text/javascript"
}
},
{
"listen": "prerequest",
"script": {
"exec": [
"let randomNumber = Math.floor(Math.random() * 100);",
"pm.collectionVariables.set(\"tempFileName\", \"new-\" + randomNumber + \"-test-temp-file.txt\");"
],
"type": "text/javascript"
}
}
],
"request": {
"auth": {
"type": "basic",
"basic": [
{
"key": "username",
"value": "[email protected]",
"type": "string"
},
{
"key": "password",
"value": "admin",
"type": "string"
}
]
},
"method": "PUT",
"header": [
{
"key": "Origin",
"value": "localhost",
"type": "text"
}
],
"body": {
"mode": "raw",
"raw": "{\n \"fileName\": \"{{tempFileName}}\",\n \"fileContent\": \"Here is some test content.\"\n}",
"options": {
"raw": {
"language": "json"
}
}
},
"url": {
"raw": "{{serverURL}}/api/v1/temp/id/non-existent-id",
"host": [
"{{serverURL}}"
],
"path": [
"api",
"v1",
"temp",
"id",
"non-existent-id"
]
}
},
"response": []
}
],
"description": "This request collection creates Temporary Files provided as plain text instead of binary files."
},
{
"name": "Upload Multiple with one wrong file",
"event": [
{
"listen": "test",
"script": {
"exec": [
"var jsonData = pm.response.json();",
"pm.test(\"Checking file names and operation status code\", function () {",
" var jsonData = pm.response.json();",
" let found = false;",
" jsonData.tempFiles.forEach((item) => {",
"",
"pm.test(\"File name check\", function () {",
" pm.expect(jsonData.tempFiles[0].fileName).to.eql('Landscape_2009_romantic_country_garden.jpeg');",
" pm.expect(jsonData.tempFiles[1].fileName).to.eql('16475687531_eac8a30914_b.jpeg');",
" pm.expect(jsonData.tempFiles[2].errorCode).to.eql('400');",
"});",
" if (item.fileName == \"Landscape_2009_romantic_country_garden.jpeg\") {",
" found = true;",
" }",
"",
" });",
" pm.expect(found).to.eq(true, \"Expected image 'Landscape_2009_romantic_country_garden.jpeg' was not found.\")",
" found = false;",
" jsonData.tempFiles.forEach((item) => {",
"",
" if (item.fileName == \"16475687531_eac8a30914_b.jpeg\") {",
" found = true;",
" }",
"",
" });",
" pm.expect(found).to.eq(true, \"Expected image '16475687531_eac8a30914_b.jpeg' was not found.\")",
" found = false;",
" jsonData.tempFiles.forEach((item) => {",
"",
" if (item.errorCode == \"400\") {",
" found = true;",
" }",
"",
" });",
" pm.expect(found).to.eq(true, \"Expected error code '400' not found.\")",
"});",
""
],
"type": "text/javascript"
Expand Down Expand Up @@ -157,5 +410,35 @@
},
"response": []
}
],
"event": [
{
"listen": "prerequest",
"script": {
"type": "text/javascript",
"exec": [
""
]
}
},
{
"listen": "test",
"script": {
"type": "text/javascript",
"exec": [
""
]
}
}
],
"variable": [
{
"key": "tempFileName",
"value": ""
},
{
"key": "tempFileId",
"value": ""
}
]
}
Loading