temp: transfert entre ordinateurs
This commit is contained in:
parent
a0d91a0ef7
commit
d81acac380
46 changed files with 18652 additions and 1328 deletions
|
|
@ -3,6 +3,9 @@ import {
|
|||
WCV3Product,
|
||||
WCV3Products,
|
||||
} from "../../web/app/themes/haiku-atelier-2024/src/scripts/lib/types/api/v3/products";
|
||||
import { BackendHeaders, getBackendHeadersFromHtml } from "./utils.ts";
|
||||
import { pipe } from "effect";
|
||||
import { not } from "effect/Boolean";
|
||||
|
||||
/*
|
||||
* Faire un premier test simple où l'on clic sur la première carte du shop
|
||||
|
|
@ -15,40 +18,50 @@ import {
|
|||
*/
|
||||
|
||||
type ProductsFixture = {
|
||||
products: WCV3Products;
|
||||
products: ProductsKinds;
|
||||
};
|
||||
|
||||
type ProductsKinds = {
|
||||
allProducts: WCV3Products;
|
||||
simpleProducts: WCV3Products;
|
||||
simpleProductsWithStock: WCV3Products;
|
||||
simpleProductsWithoutStock: WCV3Products;
|
||||
};
|
||||
|
||||
export const test = base.extend<ProductsFixture>({
|
||||
products: async ({ page, request }, use) => {
|
||||
await page.goto("/shop");
|
||||
const nonce = await page.locator("data#nonce").textContent();
|
||||
const authString = await page.locator("data#auth-string").textContent();
|
||||
|
||||
if (nonce === null || nonce === "") {
|
||||
throw new Error("Le nonce ne peut être vide.");
|
||||
}
|
||||
if (authString === null || authString === "") {
|
||||
throw new Error("L'en-tête auth-string ne peut être vide.");
|
||||
}
|
||||
const backendHeaders: BackendHeaders = await getBackendHeadersFromHtml(page);
|
||||
|
||||
const response = await request.get("/wp-json/wc/v3/products?page=1&per_page=100&status=publish", {
|
||||
headers: { Nonce: nonce, Authorization: `Basic ${authString}` },
|
||||
headers: { Nonce: backendHeaders.nonce, Authorization: `Basic ${backendHeaders.authString}` },
|
||||
});
|
||||
expect(response.ok(), "The API returned the list of every Product").toBeTruthy();
|
||||
|
||||
const products = await response.json() as WCV3Products;
|
||||
await use(products);
|
||||
const isSimpleProduct = (product: WCV3Product) => product.type === "simple";
|
||||
const hasStock = (product: WCV3Product) => (product.stock_quantity ?? 0) > 0;
|
||||
const hasNoStock = (product: WCV3Product) => pipe(hasStock(product), not);
|
||||
|
||||
const allProducts = await response.json() as WCV3Products;
|
||||
const simpleProducts = allProducts.filter(isSimpleProduct);
|
||||
const simpleProductsWithStock = simpleProducts.filter(hasStock);
|
||||
const simpleProductsWithoutStock = simpleProducts.filter(hasNoStock);
|
||||
|
||||
const kinds = {
|
||||
allProducts,
|
||||
simpleProducts,
|
||||
simpleProductsWithStock,
|
||||
simpleProductsWithoutStock,
|
||||
} satisfies ProductsKinds;
|
||||
|
||||
await use(kinds);
|
||||
},
|
||||
});
|
||||
|
||||
test("can add a Product without variation with stock to the Cart", async ({ products, page }) => {
|
||||
const simpleProducts = products.filter(p => isSimpleProduct(p) && hasQuantity(p));
|
||||
console.debug("Simple Products with stock", simpleProducts.length);
|
||||
expect(simpleProducts.length, "At least one Simple product with stock must exist").toBeGreaterThan(0);
|
||||
|
||||
// Prend un produit au hasard.
|
||||
const randomProductIndex = getRandomIntInclusive(0, simpleProducts.length - 1);
|
||||
const randomProduct = simpleProducts.at(randomProductIndex);
|
||||
const randomProductIndex = getRandomIntInclusive(0, products.simpleProductsWithStock.length - 1);
|
||||
const randomProduct = products.simpleProductsWithStock.at(randomProductIndex);
|
||||
expect(randomProduct, "The selected random Product must exist").toBeTruthy();
|
||||
if (randomProduct === undefined) {
|
||||
throw new Error("The random product can't be undefined");
|
||||
|
|
@ -81,13 +94,9 @@ test("can add a Product without variation with stock to the Cart", async ({ prod
|
|||
});
|
||||
|
||||
test("can't add a Product without variation without stock to the Cart", async ({ products, page }) => {
|
||||
const simpleProducts = products.filter(p => isSimpleProduct(p) && !hasQuantity(p));
|
||||
console.debug("Simple Products without stock", simpleProducts.length);
|
||||
expect(simpleProducts.length, "At least one Simple product without stock must exist").toBeGreaterThan(0);
|
||||
|
||||
// Prend un produit au hasard.
|
||||
const randomProductIndex = getRandomIntInclusive(0, simpleProducts.length - 1);
|
||||
const randomProduct = simpleProducts.at(randomProductIndex);
|
||||
const randomProductIndex = getRandomIntInclusive(0, products.simpleProductsWithoutStock.length - 1);
|
||||
const randomProduct = products.simpleProductsWithoutStock.at(randomProductIndex);
|
||||
expect(randomProduct, "The selected random Product must exist").toBeTruthy();
|
||||
if (randomProduct === undefined) {
|
||||
throw new Error("The random product can't be undefined");
|
||||
|
|
@ -109,6 +118,3 @@ const getRandomIntInclusive = (min: number, max: number): number => {
|
|||
|
||||
return Math.floor(Math.random() * (maxFloored - minCeiled + 1) + minCeiled);
|
||||
};
|
||||
|
||||
const isSimpleProduct = (product: WCV3Product) => product.type === "simple";
|
||||
const hasQuantity = (product: WCV3Product) => (product.stock_quantity ?? 0) > 0;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue