saleor-dashboard/cypress/utils/channelsUtils.js
Karolina fc597a7a7f
Saleor 2590 remove classes from cypress tests (#1003)
* remove classes in shipping & products utils

* remove classes

* add const

* remove getters in ProductsUtils

* remove getters in Utils

* remove getters in Utils
2021-03-12 13:14:18 +01:00

44 lines
1.3 KiB
JavaScript

import * as channels from "../apiRequests/Channels";
export function deleteChannelsStartsWith(nameStartsWith) {
channels.getChannels().then(resp => {
const channelsArray = new Set(resp.body.data.channels);
if (!channelsArray) {
return;
}
channelsArray.forEach(element => {
if (element.name.startsWith(nameStartsWith)) {
const targetChannels = Array.from(channelsArray).filter(function(
channelElement
) {
return (
element.currencyCode === channelElement.currencyCode &&
element.id !== channelElement.id
);
});
if (targetChannels[0]) {
channels.deleteChannel(element.id, targetChannels[0].id);
channelsArray.delete(element);
}
}
});
});
}
export function getDefaultChannel() {
return channels.getChannels().then(resp => {
const channelsArray = resp.body.data.channels;
return channelsArray.find(function(channelElement) {
return channelElement.slug === "default-channel";
});
});
}
export function createChannel({
isActive = true,
name,
slug = name,
currencyCode = "PLN"
}) {
return channels
.createChannel(isActive, name, slug, currencyCode)
.its("body.data.channelCreate.channel");
}