Skip to content

Commit

Permalink
Added changelog and fix in-memory deployment
Browse files Browse the repository at this point in the history
  • Loading branch information
nkaputnik committed Mar 11, 2024
1 parent 679dc57 commit 11a5812
Show file tree
Hide file tree
Showing 18 changed files with 331 additions and 6 deletions.
Binary file added db-t0.sqlite-shm
Binary file not shown.
Binary file added db-t0.sqlite-wal
Binary file not shown.
Binary file added db-t1.sqlite-shm
Binary file not shown.
Binary file added db-t1.sqlite-wal
Binary file not shown.
Binary file added db.sqlite-shm
Binary file not shown.
Empty file added db.sqlite-wal
Empty file.
1 change: 1 addition & 0 deletions ext/.cdsrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
26 changes: 26 additions & 0 deletions ext/.eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"extends": "eslint:recommended",
"env": {
"es2022": true,
"node": true,
"jest": true,
"mocha": true
},
"globals": {
"SELECT": true,
"INSERT": true,
"UPSERT": true,
"UPDATE": true,
"DELETE": true,
"CREATE": true,
"DROP": true,
"CDL": true,
"CQL": true,
"CXL": true,
"cds": true
},
"rules": {
"no-console": "off",
"require-atomic-updates": "off"
}
}
34 changes: 34 additions & 0 deletions ext/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# CAP ext
_out
*.db
*.sqlite
connection.properties
default-*.json
.cdsrc-private.json
gen/
node_modules/
target/

# Web IDE, App Studio
.che/
.gen/

# MTA
*_mta_build_tmp
*.mtar
mta_archives/

# Other
.DS_Store
*.orig
*.log

*.iml
*.flattened-pom.xml

# IDEs
# .vscode
# .idea

# @cap-js/cds-typer
@cds-models
18 changes: 18 additions & 0 deletions ext/.vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
// See https://go.microsoft.com/fwlink/?LinkId=827846 to learn about workspace recommendations.
// Extension identifier format: ${publisher}.${name}. Example: vscode.csharp

// List of extensions which should be recommended for users of this workspace.
"recommendations": [
"SAPSE.vscode-cds",
"dbaeumer.vscode-eslint",
"esbenp.prettier-vscode",
"mechatroner.rainbow-csv",
"qwtel.sqlite-viewer",
"humao.rest-client"
],
// List of extensions recommended by VS Code that should not be recommended for users of this workspace.
"unwantedRecommendations": [

]
}
20 changes: 20 additions & 0 deletions ext/.vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"version": "0.2.0",
"configurations": [
{
"name": "cds serve",
"request": "launch",
"type": "node",
"cwd": "${workspaceFolder}",
"runtimeExecutable": "cds",
"args": [
"serve",
"--with-mocks",
"--in-memory?"
],
"skipFiles": [
"<node_internals>/**"
]
}
]
}
25 changes: 25 additions & 0 deletions ext/.vscode/tasks.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"type": "shell",
"label": "cds watch",
"command": "cds",
"args": ["watch"],
"group": {
"kind": "build",
"isDefault": true
},
"problemMatcher": []
},
{
"type": "shell",
"label": "cds serve",
"command": "cds",
"args": ["serve", "--with-mocks", "--in-memory?"],
"problemMatcher": []
}
]
}
25 changes: 25 additions & 0 deletions ext/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Getting Started

Welcome to your new project.

It contains these folders and files, following our recommended project layout:

File or Folder | Purpose
---------|----------
`app/` | content for UI frontends goes here
`db/` | your domain models and data go here
`srv/` | your service models and code go here
`package.json` | project metadata and configuration
`readme.md` | this getting started guide


## Next Steps

- Open a new terminal and run `cds watch`
- (in VS Code simply choose _**Terminal** > Run Task > cds watch_)
- Start adding content, for example, a [db/schema.cds](db/schema.cds).


## Learn More

Learn more at https://cap.cloud.sap/docs/get-started/.
6 changes: 6 additions & 0 deletions ext/db/ext.cds
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
namespace x_ext; // for new entities like SalesRegion below
using from '_base';

extend sap.capire.incidents.Incidents with { foo: String};

annotate ProcessorService.Incidents with @UI.LineItem : [..., { Value: foo}];
21 changes: 21 additions & 0 deletions ext/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"name": "ext",
"version": "1.0.0",
"description": "A simple CAP project.",
"repository": "<Add your repository here>",
"license": "UNLICENSED",
"private": true,
"dependencies": {
"@sap/cds": "^7",
"express": "^4"
},
"devDependencies": {
"@cap-js/sqlite": "^1"
},
"scripts": {
"start": "cds-serve"
},
"cds": {
"extends": "_base"
}
}
17 changes: 11 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"dummy": 0
},
"dependencies": {
"@cap-js/change-tracking": "^1.0.5",
"@sap/cds": ">=7",
"@sap/cds-mtxs": "^1.9",
"express": "^4"
Expand All @@ -25,7 +26,6 @@
"chai-subset": "^1.6.0"
},
"scripts": {
"watch": "cds watch",
"start": "cds-serve",
"test": "npx jest --silent",
"add-change-tracking": "npm add @cap-js/change-tracking && cp xmpls/change-tracking.cds ./srv && cp xmpls/change-tracking.test.js ./test",
Expand Down Expand Up @@ -53,23 +53,28 @@
"[development]": {
"users": {
"alice": {
"tenant": "t1",
"roles": [
"support",
"admin",
"cds.Subscriber"
"cds.Subscriber",
"cds.ExtensionDeveloper"
]
},
"bob": {
"bob": { "tenant" : "t1",
"roles": [
"support"
]
}
}
}
},
"[local-multitenancy]": {
"multitenancy": true
}
"[production]": {
"multitenancy": true,
"extensibility": true
},
"multitenancy": true,
"extensibility": true
},
"profile": "with-mtx-sidecar"
},
Expand Down
11 changes: 11 additions & 0 deletions srv/change-tracking.cds
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using { ProcessorService.Incidents } from './services';

annotate Incidents with {
customer @changelog: [customer.name];
title @changelog;
status @changelog;
}

annotate Incidents.conversation with @changelog: [author, timestamp] {
message @changelog @Common.Label: 'Message';
}
133 changes: 133 additions & 0 deletions test/change-tracking.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
const cds = require("@sap/cds");
const { GET, POST, PATCH, DELETE , expect, axios} = cds.test(__dirname + '/..', '--with-mocks')

describe("Integration Test for ChangeTracking", () => {
let draftId,incidentId;
axios.defaults.auth = { username: "alice" };
let processorService = null;
let ChangeView = null;
beforeAll(async () => {
processorService = await cds.connect.to('ProcessorService');
ChangeView = processorService.entities.ChangeView;
});
it('Create an incident ', async () => {
const { status, statusText, data } = await POST(`/odata/v4/processor/Incidents`, {
title: 'Urgent attention required !',
status_code: 'N',
"customer": {ID:"1004100"}
});
draftId = data.ID;
expect(status).to.equal(201);
expect(statusText).to.equal('Created');
});

it('+ Activate the draft & check Urgency code as H using custom logic', async () => {
const response = await POST(
`/odata/v4/processor/Incidents(ID=${draftId},IsActiveEntity=false)/ProcessorService.draftActivate`
);
expect(response.status).to.eql(201);
expect(response.data.urgency_code).to.eql('H');
});

it('+ Test the incident status', async () => {
const { status, data: { status_code, ID } } = await GET(`/odata/v4/processor/Incidents(ID=${draftId},IsActiveEntity=true)`);
incidentId = ID;
expect(status).to.eql(200);
expect(status_code).to.eql('N');
});

it('+ Test the title detail in ChangeView', async () => {
const response = await GET(`/odata/v4/processor/Incidents?$filter=ID eq ${draftId}`);
const incidentChanges = await SELECT.from(ChangeView).where({
entity: "sap.capire.incidents.Incidents",
attribute: "title",
})
expect(incidentChanges.length).to.equal(1);
const incidentChange = incidentChanges[0];
expect(incidentChange.entityKey).to.equal(draftId);
expect(incidentChange.attribute).to.equal("title");
expect(incidentChange.modification).to.equal("create");
expect(incidentChange.valueChangedFrom).to.equal("");
expect(incidentChange.valueChangedTo).to.equal("Urgent attention required !");
});

it('+ Test the status detail in ChangeView', async () => {
const response = await GET(`/odata/v4/processor/Incidents?$filter=ID eq ${draftId}`);
const incidentChanges = await SELECT.from(ChangeView).where({
entity: "sap.capire.incidents.Incidents",
attribute: "status",
})
expect(incidentChanges.length).to.equal(1);
const incidentChange = incidentChanges[0];
expect(incidentChange.entityKey).to.equal(draftId);
expect(incidentChange.attribute).to.equal("status");
expect(incidentChange.modification).to.equal("create");
expect(incidentChange.valueChangedFrom).to.equal("");
expect(incidentChange.valueChangedTo).to.equal("N");
});

it('+ Test the customer detail in ChangeView', async () => {
const response = await GET(`/odata/v4/processor/Incidents?$filter=ID eq ${draftId}`);
const incidentChanges = await SELECT.from(ChangeView).where({
entity: "sap.capire.incidents.Incidents",
attribute: "customer",
})
expect(incidentChanges.length).to.equal(1);
const incidentChange = incidentChanges[0];
expect(incidentChange.entityKey).to.equal(draftId);
expect(incidentChange.attribute).to.equal("customer");
expect(incidentChange.modification).to.equal("create");
expect(incidentChange.valueChangedFrom).to.equal("");
expect(incidentChange.valueChangedTo).to.equal("Sunny Sunshine");
});

describe("Test Changes for Update Incident", () => {
it(`Should Close the Incident-${draftId}`, async ()=>{
const {status} = await POST(`/odata/v4/processor/Incidents(ID=${draftId},IsActiveEntity=true)/ProcessorService.draftEdit`,
{
"PreserveChanges": true
});
expect(status).to.equal(201);
});
it(`Should Close the Incident-${draftId}`, async ()=>{
const {status } = await PATCH(`/odata/v4/processor/Incidents(ID=${draftId},IsActiveEntity=false)`,{status_code: 'C'});
expect(status).to.equal(200);
});
it('+ Activate the draft & check Status code as C using custom logic', async () => {
const response = await POST(
`/odata/v4/processor/Incidents(ID=${draftId},IsActiveEntity=false)/ProcessorService.draftActivate`
);
expect(response.status).to.eql(200);
});
it('+ Test the status detail in ChangeView', async () => {
const response = await GET(`/odata/v4/processor/Incidents?$filter=ID eq ${draftId}`);
const incidentChanges = await SELECT.from(ChangeView).where({
entity: "sap.capire.incidents.Incidents",
attribute: "status",
modification: 'update',
})
expect(incidentChanges.length).to.equal(1);
const incidentChange = incidentChanges[0];
expect(incidentChange.entityKey).to.equal(draftId);
expect(incidentChange.attribute).to.equal("status");
expect(incidentChange.modification).to.equal("update");
expect(incidentChange.valueChangedFrom).to.equal("N");
expect(incidentChange.valueChangedTo).to.equal("C");
});
});

describe("Test Changes for Delete Incident", () => {
it('- Delete the Incident', async () => {
const response = await DELETE(`/odata/v4/processor/Incidents(ID=${draftId},IsActiveEntity=true)`);
expect(response.status).to.eql(204);
});

it('+ Test the status detail in ChangeView', async () => {
const incidentChanges = await SELECT.from(ChangeView).where({
entity: "sap.capire.incidents.Incidents",
attribute: "status",
})
expect(incidentChanges.length).to.equal(0);
});
});
});

0 comments on commit 11a5812

Please sign in to comment.