{"size": 2048, "ext": "js", "max_stars_repo_path": "Specification/ImageUploadFeature/Steps/new-image.step.js", "max_stars_repo_name": "sozezzo/grav.client", "max_stars_repo_stars_event_min_datetime": "2021-03-04T08:59:52.000Z", "max_stars_repo_stars_event_max_datetime": "2021-11-08T11:38:13.000Z", "max_issues_repo_path": "Specification/ImageUploadFeature/Steps/new-image.step.js", "max_issues_repo_name": "sozezzo/grav.client", "max_issues_repo_issues_event_min_datetime": "2019-01-20T00:55:45.000Z", "max_issues_repo_issues_event_max_datetime": "2020-05-05T22:05:24.000Z", "max_forks_repo_path": "Specification/ImageUploadFeature/Steps/new-image.step.js", "max_forks_repo_name": "sozezzo/grav.client", "max_forks_repo_forks_event_min_datetime": "2021-03-04T21:26:09.000Z", "max_forks_repo_forks_event_max_datetime": "2021-04-14T22:03:42.000Z"}
{"max_stars_count": 10, "max_issues_count": 16, "max_forks_count": 2, "avg_line_length": 35.9298245614, "max_line_length": 84, "alphanum_fraction": 0.7060546875}
require("jasmine");
const { When, Then, AfterAll } = require('cucumber');
const expect = require('expect');
const { imageUrl } = require('../../../Release/Common/TestDoubles/primitive-stubs');
const { join } = require('path');
const { readFileSync } = require('fs');
const World = require('../../world');
let imageNames = { bubba:'', gump:'', shrimp: '' };

let _userImages = [];

When("an image file is uploaded", async function() {
  const imagePath = join(__dirname, '../../../Common/Assets/bubba.jpg');
  const response = await this.client.saveImage(imagePath);
  imageNames.bubba = response.imageName;
  expect(response.imageName).toBeDefined();
});

Then("an encoded image is uploaded", async function() {
  const imgPath = join(__dirname, '../../../Common/Assets/gump.jpg');
  const bitmap = readFileSync(imgPath);
  const imageData = Buffer.from(bitmap).toString('base64');
  const response = await this.client.saveEncodedImage(imageData, 'jpeg');
  imageNames.gump = response.imageName;
  expect(response.imageName).toBeDefined();
});

Then("an image url is uploaded", async function() {
  const response = await this.client.saveImageUrl(imageUrl);
  imageNames.shrimp = response.imageName;
  expect(response.imageName).toBeDefined();
});

Then("the image file is found", async function() {
  const response = await this.client.userImages();
  _userImages = response.userImages;
  const image = _userImages.find(image => image.name == imageNames.bubba);
  expect(image).toBeDefined();
});

Then("the encoded image is found", async function() {
  const image = _userImages.find(image => image.name == imageNames.gump);
  expect(image).toBeDefined();
});

Then("the image url is found", async function() {
  const image = _userImages.find(image => image.name == imageNames.shrimp);
  expect(image).toBeDefined();
});

AfterAll(async () => {
  const world = new World();
  await world.client.deleteUserImage(imageNames.bubba);
  await world.client.deleteUserImage(imageNames.gump);
  await world.client.deleteUserImage(imageNames.shrimp);
})
