[JavaScript] fix index.js, ApiClient.js and test files generated to incorrect location (#2511)

remove outdated samples files
update test dependencies
This commit is contained in:
Vincent Devos
2019-03-30 03:04:44 +01:00
committed by William Cheng
parent c4d982f775
commit 8977d7b366
294 changed files with 3031 additions and 7681 deletions

View File

@@ -1,205 +1,145 @@
if (typeof module === 'object' && module.exports) {
var expect = require('expect.js');
var SwaggerPetstore = require('../../src/index');
}
/**
* OpenAPI Petstore
* This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\
*
* OpenAPI spec version: 1.0.0
*
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
* https://openapi-generator.tech
*
* OpenAPI Generator version: 4.0.0-SNAPSHOT
*
* Do not edit the class manually.
*
*/
// When testing in the Node.js environment, ApiClient will need access to a Promise constructor.
if (typeof Promise == 'undefined')
Promise = require('promise');
(function(root, factory) {
if (typeof define === 'function' && define.amd) {
// AMD.
define(['expect.js', process.cwd()+'/src/index'], factory);
} else if (typeof module === 'object' && module.exports) {
// CommonJS-like environments that support module.exports, like Node.
factory(require('expect.js'), require(process.cwd()+'/src/index'));
} else {
// Browser globals (root is window)
factory(root.expect, root.OpenApiPetstore);
}
}(this, function(expect, OpenApiPetstore) {
'use strict';
var api;
var instance;
beforeEach(function() {
api = new SwaggerPetstore.PetApi();
});
var getProperty = function(object, getter, property) {
// Use getter method if present; otherwise, get the property directly.
if (typeof object[getter] === 'function')
return object[getter]();
else
return object[property];
}
var setProperty = function(object, setter, property, value) {
// Use setter method if present; otherwise, set the property directly.
if (typeof object[setter] === 'function')
object[setter](value);
else
object[property] = value;
}
var createRandomPet = function() {
var id = new Date().getTime();
var pet = new SwaggerPetstore.Pet();
setProperty(pet, "setId", "id", id);
setProperty(pet, "setName", "name", "gorilla" + id);
var category = new SwaggerPetstore.Category();
setProperty(category, "setName", "name", "really-happy");
setProperty(pet, "setCategory", "category", category);
setProperty(pet, "setStatus", "status", "available");
var photos = ["http://foo.bar.com/1", "http://foo.bar.com/2"];
setProperty(pet, "setPhotoUrls", "photoUrls", photos);
return pet;
};
describe('PetApi', function() {
it('should create and get pet', function(done) {
var pet = createRandomPet();
api.addPet(pet)
.then(function() {
return api.getPetById(pet.id)
})
.then(function(fetched) {
expect(fetched).to.be.ok();
expect(fetched.id).to.be(pet.id);
expect(getProperty(fetched, "getPhotoUrls", "photoUrls"))
.to.eql(getProperty(pet, "getPhotoUrls", "photoUrls"));
expect(getProperty(fetched, "getCategory", "category")).to.be.ok();
expect(getProperty(getProperty(fetched, "getCategory", "category"), "getName", "name"))
.to.be(getProperty(getProperty(pet, "getCategory", "category"), "getName", "name"));
api.deletePet(pet.id);
done();
});
beforeEach(function() {
instance = new OpenApiPetstore.PetApi();
});
});
/*
@Test
public void testUpdatePet() throws Exception {
Pet pet = createRandomPet();
pet.setName("programmer");
var getProperty = function(object, getter, property) {
// Use getter method if present; otherwise, get the property directly.
if (typeof object[getter] === 'function')
return object[getter]();
else
return object[property];
}
api.updatePet(pet);
var setProperty = function(object, setter, property, value) {
// Use setter method if present; otherwise, set the property directly.
if (typeof object[setter] === 'function')
object[setter](value);
else
object[property] = value;
}
Pet fetched = api.getPetById(pet.getId());
assertNotNull(fetched);
assertEquals(pet.getId(), fetched.getId());
assertNotNull(fetched.getCategory());
assertEquals(fetched.getCategory().getName(), pet.getCategory().getName());
}
describe('PetApi', function() {
describe('addPet', function() {
it('should call addPet successfully', function(done) {
//uncomment below and update the code to test addPet
//instance.addPet(function(error) {
// if (error) throw error;
//expect().to.be();
//});
done();
});
});
describe('deletePet', function() {
it('should call deletePet successfully', function(done) {
//uncomment below and update the code to test deletePet
//instance.deletePet(function(error) {
// if (error) throw error;
//expect().to.be();
//});
done();
});
});
describe('findPetsByStatus', function() {
it('should call findPetsByStatus successfully', function(done) {
//uncomment below and update the code to test findPetsByStatus
//instance.findPetsByStatus(function(error) {
// if (error) throw error;
//expect().to.be();
//});
done();
});
});
describe('findPetsByTags', function() {
it('should call findPetsByTags successfully', function(done) {
//uncomment below and update the code to test findPetsByTags
//instance.findPetsByTags(function(error) {
// if (error) throw error;
//expect().to.be();
//});
done();
});
});
describe('getPetById', function() {
it('should call getPetById successfully', function(done) {
//uncomment below and update the code to test getPetById
//instance.getPetById(function(error) {
// if (error) throw error;
//expect().to.be();
//});
done();
});
});
describe('updatePet', function() {
it('should call updatePet successfully', function(done) {
//uncomment below and update the code to test updatePet
//instance.updatePet(function(error) {
// if (error) throw error;
//expect().to.be();
//});
done();
});
});
describe('updatePetWithForm', function() {
it('should call updatePetWithForm successfully', function(done) {
//uncomment below and update the code to test updatePetWithForm
//instance.updatePetWithForm(function(error) {
// if (error) throw error;
//expect().to.be();
//});
done();
});
});
describe('uploadFile', function() {
it('should call uploadFile successfully', function(done) {
//uncomment below and update the code to test uploadFile
//instance.uploadFile(function(error) {
// if (error) throw error;
//expect().to.be();
//});
done();
});
});
describe('uploadFileWithRequiredFile', function() {
it('should call uploadFileWithRequiredFile successfully', function(done) {
//uncomment below and update the code to test uploadFileWithRequiredFile
//instance.uploadFileWithRequiredFile(function(error) {
// if (error) throw error;
//expect().to.be();
//});
done();
});
});
});
@Test
public void testFindPetsByStatus() throws Exception {
Pet pet = createRandomPet();
pet.setName("programmer");
pet.setStatus(Pet.StatusEnum.AVAILABLE);
api.updatePet(pet);
List<Pet> pets = api.findPetsByStatus(Arrays.asList(new String[]{"available"}));
assertNotNull(pets);
boolean found = false;
for (Pet fetched : pets) {
if (fetched.getId().equals(pet.getId())) {
found = true;
break;
}
}
assertTrue(found);
}
@Test
public void testFindPetsByTags() throws Exception {
Pet pet = createRandomPet();
pet.setName("monster");
pet.setStatus(Pet.StatusEnum.AVAILABLE);
List<Tag> tags = new ArrayList<Tag>();
Tag tag1 = new Tag();
tag1.setName("friendly");
tags.add(tag1);
pet.setTags(tags);
api.updatePet(pet);
List<Pet> pets = api.findPetsByTags(Arrays.asList(new String[]{"friendly"}));
assertNotNull(pets);
boolean found = false;
for (Pet fetched : pets) {
if (fetched.getId().equals(pet.getId())) {
found = true;
break;
}
}
assertTrue(found);
}
@Test
public void testUpdatePetWithForm() throws Exception {
Pet pet = createRandomPet();
pet.setName("frank");
api.addPet(pet);
Pet fetched = api.getPetById(pet.getId());
api.updatePetWithForm(String.valueOf(fetched.getId()), "furt", null);
Pet updated = api.getPetById(fetched.getId());
assertEquals(updated.getName(), "furt");
}
@Test
public void testDeletePet() throws Exception {
Pet pet = createRandomPet();
api.addPet(pet);
Pet fetched = api.getPetById(pet.getId());
api.deletePet(fetched.getId(), null);
try {
fetched = api.getPetById(fetched.getId());
fail("expected an error");
} catch (ApiException e) {
assertEquals(404, e.getCode());
}
}
@Test
public void testUploadFile() throws Exception {
Pet pet = createRandomPet();
api.addPet(pet);
File file = new File("hello.txt");
BufferedWriter writer = new BufferedWriter(new FileWriter(file));
writer.write("Hello world!");
writer.close();
api.uploadFile(pet.getId(), "a test file", new File(file.getAbsolutePath()));
}
@Test
public void testEqualsAndHashCode() {
Pet pet1 = new Pet();
Pet pet2 = new Pet();
assertTrue(pet1.equals(pet2));
assertTrue(pet2.equals(pet1));
assertTrue(pet1.hashCode() == pet2.hashCode());
assertTrue(pet1.equals(pet1));
assertTrue(pet1.hashCode() == pet1.hashCode());
pet2.setName("really-happy");
pet2.setPhotoUrls(Arrays.asList(new String[]{"http://foo.bar.com/1", "http://foo.bar.com/2"}));
assertFalse(pet1.equals(pet2));
assertFalse(pet2.equals(pet1));
assertFalse(pet1.hashCode() == (pet2.hashCode()));
assertTrue(pet2.equals(pet2));
assertTrue(pet2.hashCode() == pet2.hashCode());
pet1.setName("really-happy");
pet1.setPhotoUrls(Arrays.asList(new String[]{"http://foo.bar.com/1", "http://foo.bar.com/2"}));
assertTrue(pet1.equals(pet2));
assertTrue(pet2.equals(pet1));
assertTrue(pet1.hashCode() == pet2.hashCode());
assertTrue(pet1.equals(pet1));
assertTrue(pet1.hashCode() == pet1.hashCode());
}
}
*/
}));