visit file;
import { sleep } from "k6";
import { environment, httpStatus, odataOpertor } from "../common/constants.js";
import { dataHelper } from "../common/dataHelper.js";
import { attributeKey, filterNameKey, fusionAuthKey, resourceKey, statusKey } from "../common/hollywood-api/keyStrings.js";
import { httpRequestCheck } from "../common/httpRequestCheck.js"
import { eventScheduleFilter } from "../common/hollywood-api/filters/eventScheduleFilter.js";
import { comingSoonMoviesFilter } from "../common/hollywood-api/filters/comingSoonMoviesFilter.js";
import { geoVenueSearchFilter } from "../common/hollywood-api/filters/geoVenueSearchFilter.js";
import { movieCarouselFeatureListFilter } from "../common/hollywood-api/filters/movieCarouselFeatureListFilter.js";
import { userProfileMoviesFilter } from "../common/hollywood-api/filters/userProfileMoviesFilter.js";
import { userProfileVenuesFilter } from "../common/hollywood-api/filters/userProfileVenuesFilter.js";
let context = {
testScenarioName: '',
comingSoonPageSize: 10,
currentCulture: '',
currentIp: '',
currentLatitude: 0,
currentLongitude: 0,
currentMovieIdList: [],
currentVenueId: null,
currentVenueIdList: [],
currentOrder: null,
currentOrderVersion: null,
currentUserId: null,
homeEndpoint: { key: resourceKey.home, value: environment.apiEndpoint },
comingSoonNextEndpoint: null,
cultureEndpoint: null,
featureListEndpoint: null,
eventEndpoint: null,
eventScheduleEndpoint: null,
movieEndpoint: null,
orderEndpoint: null,
searchEndpoint: null,
selectedEvent: null,
ticketingVenues: [],
ticketingMoviesWithVenues: [],
userEndpoint: null,
userProfileEndpoint: null,
userProfileEndpointMovies: null,
userProfileEndpointVenues: null,
geoVenueSearchEndpoint: null,
venueFeaturesEndpointList: []
};
var client = null;
var helper = null;
export class visit {
constructor(scenarioName) {
client = new httpRequestCheck();
helper = new dataHelper();
context.testScenarioName = scenarioName;
// context.currentIp = helper.getRandomConfiguredIpAddress(environment.ipLocationSearchList);
};
run(returnTicketingEvent = false, returnReservedEvent = false) {
var result = null;
result = getFusionAuthEntry();
result = getHomeDocument();
result = getCultureHomeDocument(result);
getEndpointsFromCultureHomeDocument(result);
result = getMovieCarouselFeatureList();
result = getUser();
getUserProfileEndpoint(result);
result = getGeoVenueSearch();
getCurrentVenueIdList(result);
result = getComingSoonMovies();
getCurrentMovieIdList(result);
context.comingSoonNextEndpoint = result.links.next;
result = getUserProfile();
getUserProfileEndpointsForMoviesAndVenues(result);
result = getUserProfileVenues();
result = getUserProfileMovies();
result = getEventScheduleForVenuesByPage();
sleep(environment.sleepBetweenRequestsSlow);
if (returnTicketingEvent) {
//Placeholder, will eventually return an event from the last call as a purchasable event.
}
};
getContextCopy() {
//Quick deep copy by converting to string then into new object
var contextString = JSON.stringify(context);
return JSON.parse(contextString);
}
}
function getComingSoonMovies() {
var movieFilter = new comingSoonMoviesFilter(
[ statusKey.openingThisWeek, statusKey.comingSoon ],
[ resourceKey.imageContent ],
[ attributeKey.releaseDate, attributeKey.sortName, attributeKey.id]);
return client.getRequest(context.testScenarioName,
context.movieEndpoint.value + movieFilter.toQueryString(),
context.currentCulture,
resourceKey.movie,
'',
httpStatus.ok,
environment.timeThresholdMillisecondsFast,
environment.sleepBetweenRequestsFast);
}
function getCultureHomeDocument(result) {
//Get Culture Entry Document For Random Culture in configuration
context.cultureEndpoint = helper.getRandomConfiguredCultureEndpoint(result,environment.culturesToTest);
context.currentCulture = context.cultureEndpoint.key;
return client.getRequest(context.testScenarioName,
context.cultureEndpoint.value,
context.currentCulture,
resourceKey.home,
'',
httpStatus.ok,
environment.timeThresholdMillisecondsFast,
environment.sleepBetweenRequestsFast);
}
function getCurrentVenueIdList(result) {
context.ticketingVenues = [];
context.currentVenueIdList = [];
context.venueFeaturesEndpointList = [];
result.data.forEach(r => { context.currentVenueIdList.push(r.relationships.venue.data.id); });
result.included.forEach(r => { if (r.attributes.isTicketing == true) { context.ticketingVenues.push(r.id); } });
result.included.forEach(r => {
if (context.venueFeaturesEndpointList.length < environment.discoveryVenueBrowseCount) {
context.venueFeaturesEndpointList.push(r.relationships.features.links.related);
}
});
}
function getCurrentMovieIdList(result) {
context.currentMovieIdList = [];
result.data.forEach(r => context.currentMovieIdList.push(r.id));
}
function getEndpointsFromCultureHomeDocument(result) {
context.featureListEndpoint = helper.getResourceByKey(result, resourceKey.featureList);
context.userEndpoint = helper.getResourceByKey(result, resourceKey.user);
context.geoVenueSearchEndpoint = helper.getResourceByKey(result, resourceKey.geoVenueSearch);
context.movieEndpoint = helper.getResourceByKey(result, resourceKey.movie);
context.eventEndpoint = helper.getResourceByKey(result, resourceKey.event);
context.eventScheduleEndpoint = helper.getResourceByKey(result, resourceKey.eventSchedule);
context.searchEndpoint = helper.getResourceByKey(result, resourceKey.search);
context.orderEndpoint = helper.getResourceByKey(result, resourceKey.order);
}
function getEventScheduleForVenuesByPage() {
var eventsFilter = new eventScheduleFilter(context.currentVenueIdList,
[ resourceKey.venue, resourceKey.movie, resourceKey.movie + odataOpertor.resourceSeperator + resourceKey.imageContent ],
[ attributeKey.id ],
[ attributeKey.id, attributeKey.image ],
[ attributeKey.id, attributeKey.scheduleDates ]);
var page = client.getRequest(context.testScenarioName,
context.eventScheduleEndpoint.value + eventsFilter.toQueryString(),
context.currentCulture,
resourceKey.eventSchedule,
'',
httpStatus.ok,
environment.timeThresholdMillisecondsFast,
environment.sleepBetweenRequestsFast);
context.ticketingMoviesWithVenues = [];
page.data.forEach(r => {
if ( context.ticketingVenues.includes(r.relationships.venue.data.id)) {
context.ticketingMoviesWithVenues.push( { "movieId": r.relationships.movie.data.id, "venueId": r.relationships.venue.data.id } );
}
});
while (page.links.next != undefined) {
page = client.getRequest(context.testScenarioName,
page.links.next,
context.currentCulture,
resourceKey.eventSchedule,
'',
httpStatus.ok,
environment.timeThresholdMillisecondsFast,
environment.sleepBetweenRequestsFast);
page.data.forEach(r => {
if ( context.ticketingVenues.includes(r.relationships.venue.data.id)) {
context.ticketingMoviesWithVenues.push( { "movieId": r.relationships.movie.data.id, "venueId": r.relationships.venue.data.id } );
}
});
}
}
function getFusionAuthEntry() {
return client.getRequest(context.testScenarioName,
environment.fusionAuthEndpoint + environment.fusionAuthConfigurationId,
'',
fusionAuthKey.fusionAuth,
'',
httpStatus.ok,
environment.timeThresholdMillisecondsFast,
environment.sleepBetweenRequestsFast);
}
function getGeoVenueSearch() {
var venueSearchFilter = new geoVenueSearchFilter(
environment.searchLatitude,
environment.searchLongitude,
environment.searchMinRadius,
environment.searchMaxRadius,
[
resourceKey.venue
],
[
attributeKey.name,
attributeKey.displayName,
attributeKey.urlName,
attributeKey.address,
attributeKey.location,
attributeKey.timeZone,
attributeKey.telephone,
attributeKey.isOpen,
attributeKey.isTicketing,
resourceKey.features
]
);
return client.getRequest(context.testScenarioName,
context.geoVenueSearchEndpoint.value + venueSearchFilter.toQueryString(),
context.currentCulture,
resourceKey.geoVenueSearch,
'',
httpStatus.ok,
environment.timeThresholdMillisecondsFast,
environment.sleepBetweenRequestsFast);
}
function getHomeDocument() {
return client.getRequest(context.testScenarioName,
context.homeEndpoint.value,
context.currentCulture,
resourceKey.home,
'',
httpStatus.ok,
environment.timeThresholdMillisecondsFast,
environment.sleepBetweenRequestsFast);
}
function getMovieCarouselFeatureList() {
var featureListFilter = new movieCarouselFeatureListFilter(filterNameKey.homeCarousel,
[
[ resourceKey.items, odataOpertor.resourceSeperator, resourceKey.imageContent ].join(''),
[ resourceKey.items, odataOpertor.resourceSeperator, resourceKey.actions, odataOpertor.resourceSeperator, resourceKey.items ].join('')
]);
return client.getRequest(context.testScenarioName,
context.featureListEndpoint.value + featureListFilter.toQueryString(),
context.currentCulture,
resourceKey.featureList,
'',
httpStatus.ok,
environment.timeThresholdMillisecondsFast,
environment.sleepBetweenRequestsFast);
}
function getUser() {
var userUrl = context.userEndpoint.value + '/' + environment.visitorUserId;
var result = client.getRequest(context.testScenarioName,
userUrl,
context.currentCulture,
resourceKey.user,
'',
httpStatus.ok,
environment.timeThresholdMillisecondsFast,
environment.sleepBetweenRequestsFast);
context.currentUserId = result.data.id;
return result;
}
function getUserProfile() {
return client.getRequest(context.testScenarioName,
context.userProfileEndpoint,
context.currentCulture,
resourceKey.profile,
'',
httpStatus.ok,
environment.timeThresholdMillisecondsFast,
environment.sleepBetweenRequestsFast);
}
function getUserProfileMovies() {
var moviesFilter = new userProfileMoviesFilter(
[ resourceKey.movie, resourceKey.movie + odataOpertor.resourceSeperator + resourceKey.imageContent ]
);
return client.getRequest(context.testScenarioName,
context.userProfileEndpointMovies + moviesFilter.toQueryString(),
context.currentCulture,
resourceKey.profile,
resourceKey.movie,
httpStatus.ok,
environment.timeThresholdMillisecondsFast,
environment.sleepBetweenRequestsFast);
}
function getUserProfileVenues() {
var venuesFilter = new userProfileVenuesFilter(
[ resourceKey.venue ],
[ attributeKey.id ]
);
return client.getRequest(context.testScenarioName,
context.userProfileEndpointVenues + venuesFilter.toQueryString(),
context.currentCulture,
resourceKey.profile,
resourceKey.venue,
httpStatus.ok,
environment.timeThresholdMillisecondsFast,
environment.sleepBetweenRequestsFast);
}
function getUserProfileEndpoint(result) {
context.userProfileEndpoint = result.data.relationships.profile.links.related;
}
function getUserProfileEndpointsForMoviesAndVenues(result) {
context.userProfileEndpointMovies = result.data.relationships.movies.links.related;
context.userProfileEndpointVenues = result.data.relationships.venues.links.related;
}