package com.njcn.rdms.module.system.dal.mysql.file;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.njcn.rdms.module.system.dal.dataobject.file.FileDO;
import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;

class FileMapperTest {

    @Test
    void selectByUrl_whenSignedUrl_shouldTryUnsignedPrefix() {
        FileMapper mapper = mock(FileMapper.class, invocation -> invocation.callRealMethod());
        String signedUrl = "http://oss.example.com/rdms/task/test.txt?X-Amz-Signature=abc";
        doReturn(null).when(mapper).selectFirstOne(any(), eq(signedUrl));
        doReturn(new FileDO().setId(10001L)).when(mapper).selectOne(any(Wrapper.class));

        FileDO file = mapper.selectByUrl(signedUrl);

        assertEquals(10001L, file.getId());
        verify(mapper).selectFirstOne(any(), eq(signedUrl));
        verify(mapper).selectOne(any(Wrapper.class));
    }

}
