20 lines
1.3 KiB
JavaScript
20 lines
1.3 KiB
JavaScript
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;}
|
||
});
|