← back to Goldleafwallpaper
scripts/ig-poster/test/classify-error.test.js
38 lines
'use strict';
/**
* Negative test for classify-error.js (TK-11431 amendment 3: ship a test that
* proves the check goes the RIGHT way on an injected fault).
*
* Run: node scripts/ig-poster/test/classify-error.test.js (exit 0 = pass)
*/
const assert = require('node:assert');
const { classifyPostError } = require('../classify-error');
let n = 0, fail = 0;
function check(name, got, want) {
n++;
try { assert.deepStrictEqual(got, want); console.log(` ok ${name}`); }
catch (e) { fail++; console.error(` FAIL ${name}: got ${JSON.stringify(got)} want ${JSON.stringify(want)}`); }
}
// (1) The EXACT media-fetch rejection captured in goldleaf-ig-poster.log 2026-09-17.
// This is the regression the fix exists to prevent: it must NOT be auth.
const CAPTURED_MEDIA = 'container failed: {"error":{"message":"Only photo or video can be accepted as media type.","type":"OAuthException","code":9004,"error_subcode":2207052,"is_transient":false,"error_user_title":"Media download has failed. The media URI doesn\'t meet our requirements.","error_user_msg":"The media could not be fetched from this URI: https://cdn.shopify.com/...jpg?width=500&height=400&crop=bottom"}}';
check('captured 9004 media error is MEDIA, not AUTH', classifyPostError(CAPTURED_MEDIA), { isMediaErr: true, isAuthErr: false });
// (2) A genuine token expiry MUST still classify as auth (fix must not blind the real alarm).
const REAL_EXPIRY = '{"error":{"message":"Error validating access token: Session has expired on ...","type":"OAuthException","code":190,"error_subcode":463,"fbtrace_id":"x"}}';
check('real code-190 expiry is AUTH', classifyPostError(REAL_EXPIRY), { isMediaErr: false, isAuthErr: true });
// (3) A bare OAuthException type with NO auth signal and NO media signal must NOT
// fire the re-auth alert (the old bare-`OAuth` match is exactly the bug).
const RATE_LIMIT = '{"error":{"message":"Application request limit reached","type":"OAuthException","code":4,"is_transient":true,"fbtrace_id":"y"}}';
check('rate-limit OAuthException is neither media nor auth', classifyPostError(RATE_LIMIT), { isMediaErr: false, isAuthErr: false });
// (4) Empty / non-error input is inert.
check('empty msg is inert', classifyPostError(''), { isMediaErr: false, isAuthErr: false });
check('null msg is inert', classifyPostError(null), { isMediaErr: false, isAuthErr: false });
console.log(`\n${n - fail}/${n} passed`);
process.exit(fail ? 1 : 0);