Skip to content

Commit

Permalink
chore(k6): Fix parsing error during k6 run in ci (#1158)
Browse files Browse the repository at this point in the history
* Fixed issue where concurrency test output printed was in order wrong
the
* Fixed parsing issue for invalid URI test

Related issue: #1184 

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->

## Summary by CodeRabbit

- **New Features**
	- Enhanced validation for the process property in dialog queries.
- Introduced a new function to handle batch HTTP POST requests for
service operations.
- Added a new test case for handling invalid process identifiers in
dialog searches.

- **Bug Fixes**
- Updated test cases to improve validation of invalid process inputs,
ensuring accurate error responses.

- **Documentation**
	- Minor formatting adjustments for clarity in test scripts.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->
  • Loading branch information
oskogstad authored Oct 2, 2024
1 parent f28e291 commit f2e68e8
Show file tree
Hide file tree
Showing 9 changed files with 23 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using Digdir.Domain.Dialogporten.Application.Common.Extensions.FluentValidation;
using Digdir.Domain.Dialogporten.Application.Common.Pagination;
using Digdir.Domain.Dialogporten.Application.Features.V1.Common.Localizations;
using Digdir.Domain.Dialogporten.Domain.Common;
using Digdir.Domain.Dialogporten.Domain.Localizations;
using Digdir.Domain.Dialogporten.Domain.Parties;
using Digdir.Domain.Dialogporten.Domain.Parties.Abstractions;
Expand Down Expand Up @@ -53,8 +54,8 @@ public SearchDialogQueryValidator()
RuleForEach(x => x.Status).IsInEnum();

RuleFor(x => x.Process)
.Must(x => Uri.IsWellFormedUriString(x, UriKind.Absolute))
.WithMessage("{PropertyName} must be a valid URI")
.IsValidUri()
.MaximumLength(Constants.DefaultMaxUriLength)
.When(x => x.Process is not null);
}
}
11 changes: 10 additions & 1 deletion tests/k6/common/request.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ function resolveParams(defaultParams, params) {
}

function getServiceOwnerRequestParams(params = null, tokenOptions = null) {

params = params || {};
const headers = params.Headers || {};
const hasOverridenAuthorizationHeader = headers.Authorization !== undefined;
Expand Down Expand Up @@ -62,6 +62,15 @@ export function postSO(url, body, params = null, tokenOptions = null) {
return http.post(baseUrlServiceOwner + url, body, getServiceOwnerRequestParams(params, tokenOptions));
}

export function postBatchSO(batch) {
const processedBatch = batch.map(([url, body, params]) => {
params = extend(true, {}, params, { headers: { 'Content-Type': 'application/json' }});
return ['POST', baseUrlServiceOwner + url, JSON.stringify(body), getServiceOwnerRequestParams(params)];
});

return http.batch(processedBatch);
}

export function postSOAsync(url, body, params = null, tokenOptions = null) {
body = maybeStringifyBody(body);
params = extend(true, {}, params, { headers: { 'Content-Type': 'application/json' }});
Expand Down
1 change: 1 addition & 0 deletions tests/k6/common/testimports.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export {
getSO,
postSO,
postSOAsync,
postBatchSO,
putSO,
patchSO,
deleteSO,
Expand Down
1 change: 0 additions & 1 deletion tests/k6/suites/all-single-pass.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { runAllTests } from "../tests/all-tests.js";
import { default as summary } from "../common/summary.js";
import { chai, describe } from '../common/testimports.js'


export let options = {};

export default function () {
Expand Down
2 changes: 1 addition & 1 deletion tests/k6/tests/all-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ import { default as enduserTests } from './enduser/all-tests.js';
export function runAllTests() {
serviceOwnerTests();
enduserTests();
};
};
2 changes: 1 addition & 1 deletion tests/k6/tests/enduser/dialogSearch.js
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ export default function () {
});

describe('List with invalid process filter', () => {
let r = getEU('dialogs/' + defaultFilter + '&process=?? ?');
let r = getEU('dialogs/' + defaultFilter + '&process=inval|d');
expectStatusFor(r).to.equal(400);
expect(r, 'response').to.have.validJsonBody();
expect(r.json(), 'response json').to.have.property("errors");
Expand Down
8 changes: 4 additions & 4 deletions tests/k6/tests/serviceowner/concurrency.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { describe, expect, expectStatusFor, postSO, postSOAsync, purgeSO } from '../../common/testimports.js'
import { describe, expect, expectStatusFor, postSO, postBatchSO, purgeSO } from '../../common/testimports.js'
import { default as dialogToInsert } from './testdata/01-create-dialog.js';

export default function () {
Expand All @@ -16,14 +16,14 @@ export default function () {

describe('Attempt to add a few child entities concurrently', async () => {

let promises = [];
let batch = [];

for (let i=0; i<10; i++) {
let activity = { type: "Information", performedBy: { actorType: "serviceOwner" }, description: [ { value: i.toString(), languageCode: "nb"}]};
promises.push(postSOAsync('dialogs/' + dialogId + '/activities?' + i, activity))
batch.push(['dialogs/' + dialogId + '/activities?' + i, activity]);
}

const results = await Promise.all(promises);
const results = postBatchSO(batch);

// Cleanup here, as we're in another thread
purgeSO('dialogs/' + dialogId);
Expand Down
2 changes: 1 addition & 1 deletion tests/k6/tests/serviceowner/dialogCreateInvalidProcess.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export default function (){

describe ('Attempt to create dialog with invalid URI', () => {
let dialog = dialogToInsert();
dialog.process = '?? ?';
dialog.process = 'inval|d';
let r = postSO('dialogs', dialog)
expectStatusFor(r).to.equal(400);
expect(r, 'response').to.have.validJsonBody();
Expand Down
4 changes: 2 additions & 2 deletions tests/k6/tests/serviceowner/dialogSearch.js
Original file line number Diff line number Diff line change
Expand Up @@ -176,9 +176,9 @@ export default function () {
expect(r.json(), 'response json').to.have.property("items").with.lengthOf(1);
expect(r.json().items[0], 'party').to.have.property("serviceResource").that.equals(auxResource);
});

describe('List with invalid process', () => {
let r = getSO('dialogs/?CreatedAfter=' + createdAfter + '&process=?? ?');
let r = getSO('dialogs/?CreatedAfter=' + createdAfter + '&process=inval|d');
expectStatusFor(r).to.equal(400);
expect(r, 'response').to.have.validJsonBody();
expect(r.json(), 'response json').to.have.property("errors");
Expand Down

0 comments on commit f2e68e8

Please sign in to comment.