@commercetools-test-data/utils
Version:
Data model for commercetools platform common types
60 lines (53 loc) • 1.84 kB
JavaScript
Object.defineProperty(exports, '__esModule', { value: true });
const createRelatedDates = function () {
let recentDaysFromPastReference = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 10;
const pastReference = new Date();
const getOlderDate = f => {
const refDate = new Date().toISOString();
return f.date.recent({
days: recentDaysFromPastReference,
refDate
}).toISOString();
};
const getNewerDate = f => {
const from = new Date(pastReference).toISOString();
const to = new Date().toISOString();
return f.date.between({
from,
to
}).toISOString();
};
const getFutureDate = f => f.date.future().toISOString();
return [getOlderDate, getNewerDate, getFutureDate];
};
function slugify(text) {
return text.toString().toLowerCase().replace(/\s+/g, '-') // Replace spaces with -
.replace(/[^\w-]+/g, '') // Remove all non-word chars
.replace(/--+/g, '-') // Replace multiple - with single -
.replace(/^-+/, '') // Trim - from start of text
.replace(/-+$/, ''); // Trim - from end of text
}
const getDefaultRestLocalesExpect = () => expect.objectContaining({
en: expect.any(String),
de: expect.any(String),
fr: expect.any(String)
});
const getDefaultGraphqlLocalesExpect = () => expect.arrayContaining([expect.objectContaining({
locale: 'de',
value: expect.any(String)
}), expect.objectContaining({
locale: 'en',
value: expect.any(String)
}), expect.objectContaining({
locale: 'fr',
value: expect.any(String)
})]);
var testUtils = /*#__PURE__*/Object.freeze({
__proto__: null,
getDefaultRestLocalesExpect: getDefaultRestLocalesExpect,
getDefaultGraphqlLocalesExpect: getDefaultGraphqlLocalesExpect
});
exports.createRelatedDates = createRelatedDates;
exports.slugify = slugify;
exports.testUtils = testUtils;
;