<commit_before>const chai = require('chai');
const expect = chai.expect;

const S3Bucket = require('../../src/resources/s3');

describe('s3', function utilsTest() {
	describe('_translateSpec behavior', () => {
		it('uppercase the acl field', () => {
			const s3 = new S3Bucket();
			const {attributes} = s3._translateSpec({
				metadata: {
					name: 'TestBucket',
				},
				spec: {
					acl: 'public-read'
				}
			});
			expect(attributes.ACL).to.be.equal('public-read');
		});
		it('translates all fields', () => {
			const s3 = new S3Bucket();
			const expectedResult = {
				ACL: 'private',
				CreateBucketConfiguration: {
					LocationConstraint: 'EU'
				},
				GrantFullControl: 'grantFullControl',
				GrantRead: 'grantRead',
				GrantReadACP: 'grantReadACP',
				GrantWrite: 'grantWrite',
				GrantWriteACP: 'grantWriteACP'
			};
			const {attributes} = s3._translateSpec({
				metadata: {
					name: 'TestBucket',
				},
				spec: {
					acl: 'private',
					createBucketConfiguration: {
						locationConstraint: 'EU'
					},
					grantFullControl: 'grantFullControl',
					grantRead: 'grantRead',
					grantReadACP: 'grantReadACP',
					grantWrite: 'grantWrite',
					grantWriteACP: 'grantWriteACP'
				}
			});
			expect(attributes).to.be.deep.equal(expectedResult);
		});
	});
	describe('create behavior', () => {
		it('invokes update when the bucket exists for this account', done => {
			class TestS3Bucket extends S3Bucket {
				update(bucket) {
					return Promise.resolve({updateInvoked: bucket.metadata.name});
				}

				_createBucket(bucketName, attributes) { // eslint-disable-line no-unused-vars
					const err = new Error(`Simulating ${bucketName} already owned by current account`);
					err.name = 'BucketAlreadyOwnedByYou';
					return Promise.reject(err);
				}
			}

			const bucket = {
				metadata: {
					name: 'test-bucket'
				},
				spec: {}
			};
			const bucketHandler = new TestS3Bucket();
			bucketHandler.create(bucket).then(result => {
				expect(result.updateInvoked).to.be.equal(bucket.metadata.name);
				done();
			});
		});
	});
});<commit_msg>Use async/await in the tests<commit_after>const chai = require('chai');
const expect = chai.expect;

const S3Bucket = require('../../src/resources/s3');

describe('s3', function utilsTest() {
	describe('_translateSpec behavior', () => {
		it('uppercase the acl field', () => {
			const s3 = new S3Bucket();
			const {attributes} = s3._translateSpec({
				metadata: {
					name: 'TestBucket',
				},
				spec: {
					acl: 'public-read'
				}
			});
			expect(attributes.ACL).to.be.equal('public-read');
		});
		it('translates all fields', () => {
			const s3 = new S3Bucket();
			const expectedResult = {
				ACL: 'private',
				CreateBucketConfiguration: {
					LocationConstraint: 'EU'
				},
				GrantFullControl: 'grantFullControl',
				GrantRead: 'grantRead',
				GrantReadACP: 'grantReadACP',
				GrantWrite: 'grantWrite',
				GrantWriteACP: 'grantWriteACP'
			};
			const {attributes} = s3._translateSpec({
				metadata: {
					name: 'TestBucket',
				},
				spec: {
					acl: 'private',
					createBucketConfiguration: {
						locationConstraint: 'EU'
					},
					grantFullControl: 'grantFullControl',
					grantRead: 'grantRead',
					grantReadACP: 'grantReadACP',
					grantWrite: 'grantWrite',
					grantWriteACP: 'grantWriteACP'
				}
			});
			expect(attributes).to.be.deep.equal(expectedResult);
		});
	});
	describe('create behavior', () => {
		it('invokes update when the bucket exists for this account', async() => {
			class TestS3Bucket extends S3Bucket {
				update(bucket) {
					return Promise.resolve({updateInvoked: bucket.metadata.name});
				}

				_createBucket(bucketName, attributes) { // eslint-disable-line no-unused-vars
					const err = new Error(`Simulating ${bucketName} already owned by current account`);
					err.name = 'BucketAlreadyOwnedByYou';
					return Promise.reject(err);
				}
			}

			const bucket = {
				metadata: {
					name: 'test-bucket'
				},
				spec: {}
			};
			const bucketHandler = new TestS3Bucket();
			const result = await bucketHandler.create(bucket);
			expect(result.updateInvoked).to.be.equal(bucket.metadata.name);
		});
	});
});
{'fraction_non_alphanumeric': 0.15079933190169412, 'fraction_numerical': 0.00572655690765927, 'mean_word_length': 3.238624873609707, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 14, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '741906', 'n_tokens_mistral': 1734, 'n_tokens_neox': 1298, 'n_words': 266}