Last active
September 4, 2020 14:45
-
-
Save PCreations/2223750cdb6071ec1274d268ac9530f9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import aws from "aws-sdk"; | |
aws.config.update({ | |
accessKeyId: process.env.ACCESS_KEY_ID, | |
secretAccessKey: process.env.SECRET_ACCESS_KEY, | |
region: process.env.REGION, | |
}); | |
export const createS3xmlUploader = ({ bucketName, s3 = new aws.S3() }) => { | |
let lastPutObject; | |
return { | |
upload({ domain, xmlString }) { | |
const objectToPut = { | |
Bucket: bucketName, | |
Key: `${domain}/sitemap.xml`, | |
Body: xmlString, | |
ContentType: "application/xml", | |
}; | |
return s3 | |
.putObject(objectToPut) | |
.promise() | |
.then(() => { | |
lastPutObject = objectToPut; | |
}); | |
}, | |
getLastPutObject() { | |
return lastPutObject; | |
}, | |
}; | |
}; | |
const fakeS3 = () => ({ | |
putObject() { | |
return { | |
promise() { | |
return Promise.resolve(); | |
}, | |
}; | |
}, | |
}); | |
export const createFakeS3xmlUploader = ({ bucketName }) => | |
createS3xmlUploader({ bucketName, s3: fakeS3() }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment