import test from 'node:test';import assert from 'node:assert/strict'; import {createAvatars,avatarForAccount} from '../node/avatar.mjs'; const uuid='49d2fe76-7977-4d49-bd39-e48fc8c648b8'; const request=path=>new Request('https://cp.dunerealms.com/api/avatars/'+path); test('Shared account avatar uses the face route so native profile sync never receives the skin atlas',async()=>{ const db={prepare:sql=>({bind(){return this;},first:async()=>sql.includes('avatar_key')?null:{minecraft_uuid:uuid}})}; assert.deepEqual(await avatarForAccount(db,'account'),{url:'/api/avatars/face/'+uuid,mode:'image'}); }); function fixture({skin={bytes:Buffer.from('trusted-resolver-png'),height:64},uploaded=false,linked=uuid,exists=true}={}){ const db={prepare(sql){return{bind(){return this;},async first(){if(sql.includes('SELECT avatar_key'))return uploaded?{avatar_key:uuid}:null;if(sql.includes('SELECT avatar_mime'))return null;return exists?{id:uuid,minecraft_uuid:linked}:null;}};}}; return createAvatars(db,{}, {resolver:{resolve:async value=>value===uuid?skin:null}}); } test('face rendering crops the front face and hat without changing the raw skin API',async()=>{ const api=fixture(),face=await api(request('face/'+uuid));assert.equal(face.status,200);assert.equal(face.headers.get('Content-Type'),'image/svg+xml');const svg=await face.text(); assert.match(svg,/viewBox="0 0 8 8"/);assert.match(svg,/x="-8" y="-8"/);assert.match(svg,/x="-40" y="-8"/);assert.match(svg,/data:image\/png;base64,/); const raw=await api(request('minecraft/'+uuid));assert.equal(raw.headers.get('Content-Type'),'image/png');assert.equal(await raw.text(),'trusted-resolver-png'); }); test('Java, Bedrock and legacy skins use the same resolver and correct texture height',async()=>{ for(const prefix of ['face/','face/roster/member','face/member/member']){ const path=prefix==='face/'?prefix+uuid:prefix; const svg=await (await fixture({skin:{bytes:Buffer.from('legacy'),height:32}})(request(path))).text();assert.match(svg,/height="32"/); } }); test('missing skins and unlinked accounts have a face fallback, unknown accounts remain 404',async()=>{ for(const opts of [{skin:null},{linked:null}]){const r=await fixture(opts)(request('face/roster/member'));assert.equal(r.status,200);assert.match(await r.text(),/viewBox="0 0 8 8"/);} assert.equal((await fixture({exists:false})(request('face/roster/member'))).status,404); assert.equal((await fixture()(request('face/not-a-valid-uuid'))).status,404); });