saleor-dashboard/cypress/utils/channelsUtils.js

53 lines
1.5 KiB
JavaScript
Raw Normal View History

2021-02-15 09:44:50 +00:00
import Channels from "../apiRequests/Channels";
class ChannelsUtils {
channels = new Channels();
2021-02-22 12:10:51 +00:00
createdChannel;
2021-02-15 09:44:50 +00:00
deleteChannels(nameStartsWith) {
this.channels.getChannels().then(resp => {
const channelsArray = new Set(resp.body.data.channels);
2021-02-17 11:22:24 +00:00
if (!channelsArray) {
return;
2021-02-15 09:44:50 +00:00
}
2021-02-17 11:22:24 +00:00
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]) {
this.channels.deleteChannel(element.id, targetChannels[0].id);
channelsArray.delete(element);
}
}
});
2021-02-15 09:44:50 +00:00
});
}
getDefaultChannel() {
return this.channels.getChannels().then(resp => {
const channelsArray = resp.body.data.channels;
return (this.defaultChannel = channelsArray.find(function(
channelElement
) {
return channelElement.slug === "default-channel";
}));
});
}
2021-02-24 13:21:19 +00:00
createChannel({ isActive = true, name, slug = name, currencyCode = "PLN" }) {
2021-02-22 12:10:51 +00:00
return this.channels
.createChannel(isActive, name, slug, currencyCode)
.then(
resp => (this.createdChannel = resp.body.data.channelCreate.channel)
);
}
getCreatedChannel() {
2021-02-24 13:21:19 +00:00
return this.createdChannel;
2021-02-22 12:10:51 +00:00
}
2021-02-15 09:44:50 +00:00
}
export default ChannelsUtils;