Skip to content

Commit

Permalink
wip e2e
Browse files Browse the repository at this point in the history
  • Loading branch information
Fargekritt committed Sep 11, 2024
1 parent eed179e commit 16d54f1
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -397,25 +397,24 @@ public CreateDialogDialogActivityDtoValidator(
.When(x => x.Type != DialogActivityType.Values.Information);
RuleFor(x => x.TransmissionId)
.Null()
// .WithMessage($"{nameof(DialogActivityType.Values.DialogOpened)} is not allowed on a transmission.")
.WithMessage($"A {nameof(DialogActivityType.Values.DialogOpened)} activity cannot reference a transmission.") // er det dette "rett" feilmelding?
.When(x => x.Type == DialogActivityType.Values.DialogOpened);
// Testene feilet av denne. var den for streng?
// Sier jeg her at når transmissionId != null MÅ Type == TransmissionOpened?
// Sier ikke den fra notification det samme?
// RuleFor(x => x.TransmissionId)
// .NotNull()
// .WithMessage($"A {nameof(DialogActivityType.Values.TransmissionOpened)} needs to reference a transmission.")
// .When(x => x.Type == DialogActivityType.Values.TransmissionOpened);
RuleFor(x => x.TransmissionId)
.NotNull()
.WithMessage($"A {nameof(DialogActivityType.Values.TransmissionOpened)} needs to reference a transmission.")
.When(x => x.Type == DialogActivityType.Values.TransmissionOpened);
// ====================== REF FRA NOTIFI =========
// RuleFor(x => x.TransmissionId)
// .NotNull()
// .NotEqual(default(Guid))
// .When(x => x.ActivityType == DialogActivityType.Values.TransmissionOpened);
// ===================== END REF ===================
RuleFor(x => x.Type)
.Equal(DialogActivityType.Values.TransmissionOpened)
.When(x => x.TransmissionId != null);
// RuleFor(x => x.Type)
// .Equal(DialogActivityType.Values.TransmissionOpened)
// .When(x => x.TransmissionId != null);
}
}

Expand Down
15 changes: 15 additions & 0 deletions tests/k6/common/dialog.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,21 @@ export function setVisibleFrom(dialog, visibleFrom) {
dialog.visibleFrom = visibleFrom;
}

export function setActivities(dialog, activities) {
if (activities == null) {
delete dialog.activities;
return;
}
dialog.activities = activities;
}

export function addActivity(dialog, activity) {
if (activity == null) return;
if (dialog.activities == null) {
dialog.activities = [];
}
}

function dateToUTCString(date) {
let dateStr = date.toISOString();
const ms = ('000' + date.getUTCMilliseconds()).slice(-3);
Expand Down
4 changes: 3 additions & 1 deletion tests/k6/common/testimports.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,7 @@ export {
setParty,
setDueAt,
setExpiresAt,
setVisibleFrom
setVisibleFrom,
setActivities,
addActivity
} from './dialog.js';
41 changes: 39 additions & 2 deletions tests/k6/tests/serviceowner/dialogCreatePatchDelete.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { describe, expect, expectStatusFor, getSO, postSO, purgeSO, patchSO, uuidv4 } from '../../common/testimports.js'
import { describe, expect, expectStatusFor, getSO, postSO, purgeSO, patchSO, uuidv4, uuidv7,setActivities, addActivity } from '../../common/testimports.js'
import { default as dialogToInsert } from './testdata/01-create-dialog.js';

export default function () {
Expand Down Expand Up @@ -73,4 +73,41 @@ export default function () {
let r = purgeSO('dialogs/' + dialogId);
expectStatusFor(r).to.equal(204);
});
}

describe('Perform dialog create with invalid activity', () => {
let dialog = dialogToInsert();
let r = postSO('dialogs', dialog);
expectStatusFor(r).to.equal(201);
expect(r, 'response').to.have.validJsonBody();
expect(r.json(), 'response json').to.match(/^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$/)
dialogId = r.json();

r = getSO('dialogs/' + dialogId + '/transmissions');
expectStatusFor(r).to.equal(200);
expect(r, 'response').to.have.validJsonBody();
expect(r.json()[0], 'response json').to.have.property('id');
let transmissionId = r.json()[0].id;
// let transmission = {
// 'type': 'Information',
// 'sender': {
// "actor"
// }
// }
let activities = [{
'id': uuidv7(),
'type': 'DialogOpened',
'transmissionId': uuidv7(),
'performedBy': {
'actorType': 'ServiceOwner'
}
}]
console.log(activities);
setActivities(dialog, activities);
r = postSO('dialogs', dialog);
expectStatusFor(r).to.equal(201);
expect(r, 'response').to.have.validJsonBody();
expect(r.json(), 'response json').to.match(/^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$/)

dialogId = r.json();
});
}

0 comments on commit 16d54f1

Please sign in to comment.