Skip to content

Commit

Permalink
Add a use case test for smsOrder with orgNo (#711)
Browse files Browse the repository at this point in the history
  • Loading branch information
sigridbra authored Feb 14, 2025
1 parent a6c31ba commit 1d557ef
Showing 1 changed file with 57 additions and 1 deletion.
58 changes: 57 additions & 1 deletion test/k6/src/tests/orders_org_no.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

import { check, sleep } from "k6";
import { stopIterationOnFail } from "../errorhandler.js";
import { uuidv4 } from "https://jslib.k6.io/k6-utils/1.4.0/index.js";
import { randomString, uuidv4 } from "https://jslib.k6.io/k6-utils/1.4.0/index.js";

import * as setupToken from "../setup.js";
import * as ordersApi from "../api/notifications/orders.js";
Expand Down Expand Up @@ -56,8 +56,15 @@ export function setup() {

const emailOrderRequest = { ...emailOrderRequestJson, sendersReference, resourceId, recipients: [] };

const smsOrderRequest = {
senderNumber: "Altinn",
body: "This is an automated test: " + randomString(30) + " " + randomString(30),
recipients: [],
sendersReference: sendersReference
};
if (orgNoRecipient) {
emailOrderRequest.recipients.push({ organizationNumber: orgNoRecipient });
smsOrderRequest.recipients.push({ organizationNumber: orgNoRecipient })
}

const runFullTestSet = __ENV.runFullTestSet
Expand All @@ -69,6 +76,7 @@ export function setup() {
runFullTestSet,
sendersReference,
emailOrderRequest,
smsOrderRequest,
};
}

Expand Down Expand Up @@ -99,6 +107,33 @@ function postEmailNotificationOrderRequest(data) {
return selfLink;
}

/**
* Posts an SMS notification order request.
* @param {Object} data - The data object containing smsOrderRequest and token.
* @returns {string} The selfLink of the created order.
*/
function postSmsNotificationOrderRequest(data) {
const response = ordersApi.postSmsNotificationOrder(
JSON.stringify(data.smsOrderRequest),
data.token
);

const success = check(response, {
"POST SMS notification order request. Status is 202 Accepted": (r) => r.status === 202
});

stopIterationOnFail("POST SMS notification order request failed", success);

const selfLink = response.headers["Location"];

check(response, {
"POST SMS notification order request. Location header provided": (_) => selfLink,
"POST SMS notification order request. Response body is not an empty string": (r) => r.body
});

return selfLink;
}

/**
* Gets the email notification summary.
* @param {Object} data - The data object containing token.
Expand Down Expand Up @@ -139,6 +174,23 @@ function getEmailNotificationSummaryAgainAfterOneMinuteForVerification(data, ord
});
}

/**
* Gets the SMS notification summary.
* @param {Object} data - The data object containing token.
* @param {string} orderId - The ID of the order.
*/
function getSmsNotificationSummary(data, orderId) {
const response = notificationsApi.getSmsNotifications(orderId, data.token);

check(response, {
"GET SMS notifications. Status is 200 OK": (r) => r.status === 200,
});

check(JSON.parse(response.body), {
"GET SMS notifications. OrderId property is a match": (notificationSummary) => notificationSummary.orderId === orderId,
});
}

/**
* The main function to run the test.
* @param {Object} data - The data object containing runFullTestSet and other test data.
Expand All @@ -147,7 +199,11 @@ export default function (data) {
const selfLink = postEmailNotificationOrderRequest(data);
const id = selfLink.split("/").pop();

const smsSelfLink = postSmsNotificationOrderRequest(data);
const smsId = smsSelfLink.split("/").pop();

getEmailNotificationSummary(data, id);
getSmsNotificationSummary(data, smsId);

if (data.runFullTestSet) {
getEmailNotificationSummaryAgainAfterOneMinuteForVerification(data, id);
Expand Down

0 comments on commit 1d557ef

Please sign in to comment.