fix: distinguish email service errors and validate send receipts

This commit is contained in:
2026-09-06 14:16:08 +03:00
parent a25dcb7a5d
commit e711da9567
5 changed files with 66 additions and 32 deletions
+19
View File
@@ -0,0 +1,19 @@
import test from 'node:test';
import assert from 'node:assert/strict';
import {emailConfiguration,sendEmailTest} from '../src/services/emailNotifications.js';
test('email configuration errors differ from an explicitly unconfigured service',async()=>{
const fetch=globalThis.fetch;
try{
globalThis.fetch=async()=>Response.json({success:false,error:'Unavailable'},{status:503});await assert.rejects(emailConfiguration(),/Unavailable/);
globalThis.fetch=async()=>Response.json({success:true,configured:false});assert.equal((await emailConfiguration()).configured,false);
globalThis.fetch=async()=>Response.json({success:true});await assert.rejects(emailConfiguration(),/doğrulanamadı/);
}finally{globalThis.fetch=fetch;}
});
test('email test requires HTTP success and a provider receipt, without retrying',async()=>{
const fetch=globalThis.fetch;let calls=0;
try{
globalThis.fetch=async()=>{calls++;return Response.json({success:true,to:'qa@example.test'});};await assert.rejects(sendEmailTest([]),/posta kutunuzu/);assert.equal(calls,1);
globalThis.fetch=async()=>Response.json({success:true,id:'qa-id',to:'qa@example.test'},{status:502});await assert.rejects(sendEmailTest([]));
globalThis.fetch=async()=>Response.json({success:true,id:'qa-id',to:'qa@example.test'});assert.equal((await sendEmailTest([])).id,'qa-id');
}finally{globalThis.fetch=fetch;}
});