My function to get a preSigned URL:

const awsPresigner = require('@aws-sdk/s3-request-presigner');

const getPresignedUrl = (fileName, action) => {
  const command = getCommand(fileName, action); // get aws command

  const s3Client = new S3Client({
    credentials: {
      accessKeyId: process.env.AWS_PUBLIC_KEY,
      secretAccessKey: process.env.AWS_PRIVATE_KEY,
    },
    region: process.env.AWS_REGION,
  });

  return awsPresigner.getSignedUrl(s3Client, command, {
    expiresIn: constants.PRESIGNED_URL_EXPIRES_IN * 60,
  });
};

and in UT function, I tried mock this function by sinon stub:

const sinon = require('sinon');
const expect = require('chai').expect;
const awsPresigner = require('@aws-sdk/s3-request-presigner');

  describe('Tests getPresignedUrl API', () => {
    let getPresignedUrlStub;
    beforeEach(() => {
      getPresignedUrlStub = sinon.stub(awsPresigner, 'getSignedUrl');
    });
    afterEach(() => {
      getPresignedUrlStub.restore();
    });

    it('should return SUCCESSFUL with a presignedURL', async () => {
      getPresignedUrlStub.resolves('http://fake-url.com');
      const response = await getPresignedUrl('IMG75411705302487970.jpg', 'putObject');
      expect(response).to.be.equal('http://fake-url.com');
    });
  });

I expect this UT is success, but the result still be a real url https://s3.us-west-2.amazonaws.com/IMG75411705302487970.jpg?X-Amz-Algorithm......