Skip to content

Commit

Permalink
add tests for delete with update
Browse files Browse the repository at this point in the history
  • Loading branch information
Doris Lam committed Oct 22, 2022
1 parent 8e5ac78 commit 4252608
Show file tree
Hide file tree
Showing 3 changed files with 246 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,17 +1,30 @@
package org.openmbee.mms.core.objects;

import io.swagger.v3.oas.annotations.media.Schema;
import org.openmbee.mms.json.ElementJson;

import java.util.List;

public class ElementsCommitResponse extends ElementsResponse {

@Schema(nullable = true)
private String commitId;

private List<ElementJson> deleted;
public String getCommitId() {
return commitId;
}

public void setCommitId(String commitId) {
this.commitId = commitId;
}

public List<ElementJson> getDeleted() {
return deleted;
}

public ElementsResponse setDeleted(List<ElementJson> deleted) {
this.deleted = deleted;
return this;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,8 @@ public ElementsCommitResponse createOrUpdate(String projectId, String refId, Ele
ElementsCommitResponse response = new ElementsCommitResponse();
response.getElements().addAll(info.getUpdatedMap().values());
response.setRejected(new ArrayList<>(info.getRejected().values()));
if(!info.getUpdatedMap().isEmpty()) {
response.setDeleted(new ArrayList<>(info.getDeletedMap().values()));
if(!info.getUpdatedMap().isEmpty() || !info.getDeletedMap().isEmpty()) {
response.setCommitId(info.getCommitJson().getId());
}
return response;
Expand Down
231 changes: 231 additions & 0 deletions example/crud.postman_collection.json
Original file line number Diff line number Diff line change
Expand Up @@ -3563,6 +3563,237 @@
}
},
"response": []
},
{
"name": "create project zz",
"event": [
{
"listen": "test",
"script": {
"exec": [
"pm.test(\"Status code is 200\", function () {",
" pm.response.to.have.status(200);",
"});"
],
"type": "text/javascript"
}
}
],
"request": {
"method": "POST",
"header": [
{
"key": "Content-Type",
"type": "text",
"value": "application/json"
}
],
"body": {
"mode": "raw",
"raw": "{\n\t\"projects\": [\n\t\t{\n\t\t\t\"id\": \"zz\", \n\t\t\t\"name\": \"zz\",\n\t\t\t\"orgId\": \"a\",\n\t\t\t\"schema\": \"default\"\n\t\t}\n\t]\n}"
},
"url": {
"raw": "{{host}}/projects",
"host": [
"{{host}}"
],
"path": [
"projects"
]
}
},
"response": []
},
{
"name": "add elements to project zz",
"event": [
{
"listen": "test",
"script": {
"exec": [
"pm.test(\"Status code is 200\", function () {",
" pm.response.to.have.status(200);",
"});"
],
"type": "text/javascript"
}
}
],
"request": {
"method": "POST",
"header": [
{
"key": "Content-Type",
"type": "text",
"value": "application/json"
}
],
"body": {
"mode": "raw",
"raw": "{\n\t\"elements\": [\n\t\t{\n\t\t\t\"id\": \"x\",\n\t\t\t\"name\": \"x\"\n\t\t}, {\n\t\t\t\"id\": \"y\", \n\t\t\t\"name\": \"y\"\n\t\t}, {\n\t\t\t\"id\": \"z\",\n\t\t\t\"name\": \"z\"\n\t\t}\n\t]\n}"
},
"url": {
"raw": "{{host}}/projects/zz/refs/master/elements",
"host": [
"{{host}}"
],
"path": [
"projects",
"zz",
"refs",
"master",
"elements"
]
}
},
"response": []
},
{
"name": "update and delete elements in same commit",
"event": [
{
"listen": "test",
"script": {
"exec": [
"pm.test(\"response has elements\", function () {",
" var jsonData = pm.response.json();",
" pm.expect(jsonData.elements.length).to.eql(2);",
" pm.expect(jsonData.deleted.length).to.eql(1);",
"});",
"",
"pm.environment.set(\"hybridCommit\", pm.response.json().commitId);"
],
"type": "text/javascript"
}
}
],
"request": {
"method": "POST",
"header": [
{
"key": "Content-Type",
"type": "text",
"value": "application/json"
}
],
"body": {
"mode": "raw",
"raw": "{\n\t\"elements\": [\n\t\t{\n\t\t\t\"id\": \"x\",\n\t\t\t\"name\": \"xx\"\n\t\t}, {\n\t\t\t\"id\": \"y\", \n\t\t\t\"name\": \"yy\"\n\t\t}\n\t],\n \"deletes\": [{\"id\": \"z\"}]\n}"
},
"url": {
"raw": "{{host}}/projects/zz/refs/master/elements",
"host": [
"{{host}}"
],
"path": [
"projects",
"zz",
"refs",
"master",
"elements"
]
}
},
"response": []
},
{
"name": "get deleted element",
"event": [
{
"listen": "test",
"script": {
"exec": [
"pm.test(\"Status code is 410\", function () {",
" pm.response.to.have.status(410);",
"});"
],
"type": "text/javascript"
}
}
],
"protocolProfileBehavior": {
"disableBodyPruning": true
},
"request": {
"method": "GET",
"header": [
{
"key": "Content-Type",
"type": "text",
"value": "application/json"
}
],
"body": {
"mode": "raw",
"raw": "{\n\t\"elements\": [\n\t\t{\n\t\t\t\"id\": \"x\",\n\t\t\t\"name\": \"xx\"\n\t\t}, {\n\t\t\t\"id\": \"y\", \n\t\t\t\"name\": \"yy\"\n\t\t}\n\t],\n \"deletes\": [{\"id\": \"z\"}]\n}"
},
"url": {
"raw": "{{host}}/projects/zz/refs/master/elements/z",
"host": [
"{{host}}"
],
"path": [
"projects",
"zz",
"refs",
"master",
"elements",
"z"
]
}
},
"response": []
},
{
"name": "get commit object",
"event": [
{
"listen": "test",
"script": {
"exec": [
"pm.test(\"commit has right data\", function () {",
" var jsonData = pm.response.json();",
" pm.expect(jsonData.commits[0].updated.length).to.eql(2);",
" pm.expect(jsonData.commits[0].deleted.length).to.eql(1);",
"",
"});",
"",
""
],
"type": "text/javascript"
}
}
],
"protocolProfileBehavior": {
"disableBodyPruning": true
},
"request": {
"method": "GET",
"header": [
{
"key": "Content-Type",
"type": "text",
"value": "application/json"
}
],
"body": {
"mode": "raw",
"raw": "{\n\t\"elements\": [\n\t\t{\n\t\t\t\"id\": \"x\",\n\t\t\t\"name\": \"xx\"\n\t\t}, {\n\t\t\t\"id\": \"y\", \n\t\t\t\"name\": \"yy\"\n\t\t}\n\t],\n \"deletes\": [{\"id\": \"z\"}]\n}"
},
"url": {
"raw": "{{host}}/projects/zz/commits/{{hybridCommit}}",
"host": [
"{{host}}"
],
"path": [
"projects",
"zz",
"commits",
"{{hybridCommit}}"
]
}
},
"response": []
}
],
"auth": {
Expand Down

0 comments on commit 4252608

Please sign in to comment.