Compare commits
2 Commits
0d6ef40c8e
...
5883dc6298
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
5883dc6298 | ||
|
|
7e3d0be595 |
@@ -1,5 +1,13 @@
|
|||||||
|
const applyProductDisplayAlias = (name) => {
|
||||||
|
const productName = String(name || '').trim();
|
||||||
|
return productName
|
||||||
|
.replace(/^BASE LISA CAMISETA\b/i, 'CAMISETA PREMIUM')
|
||||||
|
.replace(/^BASE LISA OVER SIZE\b/i, 'CAMISETA PREMIUM OVER SIZE')
|
||||||
|
.replace(/^BASE LISA MOLETOM CANGURU\b/i, 'MOLETOM CANGURU PREMIUM');
|
||||||
|
};
|
||||||
|
|
||||||
const formatProductNameForDisplay = (name) => {
|
const formatProductNameForDisplay = (name) => {
|
||||||
return String(name || '')
|
return applyProductDisplayAlias(name)
|
||||||
.toLocaleLowerCase('pt-BR')
|
.toLocaleLowerCase('pt-BR')
|
||||||
.replace(/(^|[\s/-])(\p{L})/gu, (_, separator, letter) => {
|
.replace(/(^|[\s/-])(\p{L})/gu, (_, separator, letter) => {
|
||||||
return `${separator}${letter.toLocaleUpperCase('pt-BR')}`;
|
return `${separator}${letter.toLocaleUpperCase('pt-BR')}`;
|
||||||
@@ -9,11 +17,7 @@ const formatProductNameForDisplay = (name) => {
|
|||||||
const formatProductList = (productNames) => {
|
const formatProductList = (productNames) => {
|
||||||
const displayNames = productNames.map(formatProductNameForDisplay);
|
const displayNames = productNames.map(formatProductNameForDisplay);
|
||||||
|
|
||||||
if (displayNames.length <= 2) {
|
return displayNames.join(' • ');
|
||||||
return displayNames.join(' e ');
|
|
||||||
}
|
|
||||||
|
|
||||||
return `${displayNames.slice(0, -1).join(', ')} e ${displayNames[displayNames.length - 1]}`;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const groupCampaignRowsByBaseProduct = (rows) => {
|
const groupCampaignRowsByBaseProduct = (rows) => {
|
||||||
|
|||||||
@@ -25,24 +25,39 @@ const row = (overrides) => ({
|
|||||||
...overrides
|
...overrides
|
||||||
});
|
});
|
||||||
|
|
||||||
test('formatProductList uses Portuguese list joining', () => {
|
test('formatProductList uses inline bullet separators', () => {
|
||||||
assert.equal(formatProductList([]), '');
|
assert.equal(formatProductList([]), '');
|
||||||
assert.equal(formatProductList(['BONÉ - PRETO']), 'Boné - Preto');
|
assert.equal(formatProductList(['BONÉ - PRETO']), 'Boné - Preto');
|
||||||
assert.equal(formatProductList(['BONÉ - PRETO', 'BASE BRANCA']), 'Boné - Preto e Base Branca');
|
assert.equal(formatProductList(['BONÉ - PRETO', 'BASE BRANCA']), 'Boné - Preto • Base Branca');
|
||||||
assert.equal(
|
assert.equal(
|
||||||
formatProductList(['BONÉ - PRETO', 'BASE BRANCA', 'BASE PRETA']),
|
formatProductList(['BONÉ - PRETO', 'BASE BRANCA', 'BASE PRETA']),
|
||||||
'Boné - Preto, Base Branca e Base Preta'
|
'Boné - Preto • Base Branca • Base Preta'
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('formatProductNameForDisplay converts campaign product names to title case', () => {
|
test('formatProductNameForDisplay converts campaign product names to title case', () => {
|
||||||
assert.equal(
|
assert.equal(
|
||||||
formatProductNameForDisplay('BASE LISA MOLETOM CANGURU COR PRETO'),
|
formatProductNameForDisplay('BASE LISA MOLETOM CANGURU COR PRETO'),
|
||||||
'Base Lisa Moletom Canguru Cor Preto'
|
'Moletom Canguru Premium Cor Preto'
|
||||||
);
|
);
|
||||||
assert.equal(formatProductNameForDisplay('BONÉ - BRANCO'), 'Boné - Branco');
|
assert.equal(formatProductNameForDisplay('BONÉ - BRANCO'), 'Boné - Branco');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('formatProductNameForDisplay applies customer-facing campaign aliases', () => {
|
||||||
|
assert.equal(
|
||||||
|
formatProductNameForDisplay('BASE LISA CAMISETA COR AZUL'),
|
||||||
|
'Camiseta Premium Cor Azul'
|
||||||
|
);
|
||||||
|
assert.equal(
|
||||||
|
formatProductNameForDisplay('BASE LISA OVER SIZE COR PRETO'),
|
||||||
|
'Camiseta Premium Over Size Cor Preto'
|
||||||
|
);
|
||||||
|
assert.equal(
|
||||||
|
formatProductNameForDisplay('BASE LISA MOLETOM CANGURU COR PRETO'),
|
||||||
|
'Moletom Canguru Premium Cor Preto'
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
test('mapCampaignProducts accumulates split deltas by base product', () => {
|
test('mapCampaignProducts accumulates split deltas by base product', () => {
|
||||||
const groups = groupCampaignRowsByBaseProduct([
|
const groups = groupCampaignRowsByBaseProduct([
|
||||||
row({ id: 1, delta_estoque: 10, produto_id: 'SKU-P', nome: 'Produto Split TAMANHO - P' }),
|
row({ id: 1, delta_estoque: 10, produto_id: 'SKU-P', nome: 'Produto Split TAMANHO - P' }),
|
||||||
@@ -79,7 +94,7 @@ test('buildWhatsappCampaignPayload combines multiple ready products into one mes
|
|||||||
]));
|
]));
|
||||||
const payload = buildWhatsappCampaignPayload(products, [{ nome: 'Cliente', fone: '5511999999999' }]);
|
const payload = buildWhatsappCampaignPayload(products, [{ nome: 'Cliente', fone: '5511999999999' }]);
|
||||||
|
|
||||||
assert.equal(payload.productsText, 'Boné - Preto e Base Lisa Camiseta Cor Branco');
|
assert.equal(payload.productsText, 'Boné - Preto • Camiseta Premium Cor Branco');
|
||||||
assert.equal(payload.baseProduct, payload.productsText);
|
assert.equal(payload.baseProduct, payload.productsText);
|
||||||
assert.equal(payload.total_delta, 200);
|
assert.equal(payload.total_delta, 200);
|
||||||
assert.equal(payload.products.length, 2);
|
assert.equal(payload.products.length, 2);
|
||||||
|
|||||||
Reference in New Issue
Block a user