forked from loafle/openapi-generator-original
Fixed ObjectSerializer test
This commit is contained in:
parent
69dfdd57a6
commit
878ea6e1c1
1
samples/client/petstore/typescript/tests/default/.gitignore
vendored
Normal file
1
samples/client/petstore/typescript/tests/default/.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
||||
dist
|
@ -1,46 +0,0 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
var ts_petstore_client_1 = require("ts-petstore-client");
|
||||
var ts_petstore_client_2 = require("ts-petstore-client");
|
||||
var chai_1 = require("chai");
|
||||
describe("Security Authentication", function () {
|
||||
describe("No Authentication", function () {
|
||||
it("No Authentication", function () {
|
||||
var ctx = new ts_petstore_client_2.RequestContext("http://google.com", ts_petstore_client_2.HttpMethod.GET);
|
||||
var noAuth = new ts_petstore_client_1.NoAuthentication();
|
||||
noAuth.applySecurityAuthentication(ctx);
|
||||
chai_1.expect(ctx.getUrl()).to.equal("http://google.com");
|
||||
chai_1.expect(ctx.getHeaders()).to.deep.equal({});
|
||||
chai_1.expect(ctx.getBody()).to.equal("");
|
||||
});
|
||||
});
|
||||
describe("API Key Authentication", function () {
|
||||
// TODO: make all params const variables
|
||||
it("Header API Key", function () {
|
||||
var ctx = new ts_petstore_client_2.RequestContext("http://google.com", ts_petstore_client_2.HttpMethod.GET);
|
||||
var auth = new ts_petstore_client_1.APIKeyAuthentication("my_name", "paramName", "header", "apiKey");
|
||||
auth.applySecurityAuthentication(ctx);
|
||||
chai_1.expect(ctx.getUrl()).to.equal("http://google.com");
|
||||
chai_1.expect(ctx.getHeaders()).to.have.property("paramName");
|
||||
chai_1.expect(ctx.getHeaders()["paramName"]).to.equal("apiKey");
|
||||
chai_1.expect(ctx.getBody()).to.equal("");
|
||||
});
|
||||
it("Query API Key", function () {
|
||||
var ctx = new ts_petstore_client_2.RequestContext("http://google.com?a=b", ts_petstore_client_2.HttpMethod.GET);
|
||||
var auth = new ts_petstore_client_1.APIKeyAuthentication("my_name", "paramName", "query", "apiKey");
|
||||
auth.applySecurityAuthentication(ctx);
|
||||
chai_1.expect(ctx.getUrl()).to.contain("paramName=apiKey");
|
||||
chai_1.expect(ctx.getHeaders()).to.deep.equal({});
|
||||
chai_1.expect(ctx.getBody()).to.equal("");
|
||||
});
|
||||
it("Cookie API Key", function () {
|
||||
var ctx = new ts_petstore_client_2.RequestContext("http://google.com", ts_petstore_client_2.HttpMethod.GET);
|
||||
var auth = new ts_petstore_client_1.APIKeyAuthentication("my_name", "paramName", "cookie", "apiKey");
|
||||
auth.applySecurityAuthentication(ctx);
|
||||
chai_1.expect(ctx.getUrl()).to.equal("http://google.com");
|
||||
chai_1.expect(ctx.getHeaders()).to.have.property("Cookie");
|
||||
chai_1.expect(ctx.getHeaders()["Cookie"]).to.contain("paramName=apiKey; ");
|
||||
chai_1.expect(ctx.getBody()).to.equal("");
|
||||
});
|
||||
});
|
||||
});
|
@ -1,64 +0,0 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
var ts_petstore_client_1 = require("ts-petstore-client");
|
||||
var chai_1 = require("chai");
|
||||
var FormData = require("form-data");
|
||||
var libs = {
|
||||
"isomorphic-fetch": new ts_petstore_client_1.IsomorphicFetchHttpLibrary()
|
||||
};
|
||||
var _loop_1 = function (libName) {
|
||||
var lib = libs[libName];
|
||||
describe("Isomorphic Fetch", function () {
|
||||
it("GET-Request", function (done) {
|
||||
var requestContext = new ts_petstore_client_1.RequestContext("http://httpbin.org/get", ts_petstore_client_1.HttpMethod.GET);
|
||||
requestContext.setHeaderParam("X-Test-Token", "Test-Token");
|
||||
requestContext.addCookie("test-cookie", "cookie-value");
|
||||
lib.send(requestContext).then(function (resp) {
|
||||
chai_1.expect(resp.httpStatusCode, "Expected status code to be 200").to.eq(200);
|
||||
var body = JSON.parse(resp.body);
|
||||
chai_1.expect(body["headers"]).to.exist;
|
||||
chai_1.expect(body["headers"]["X-Test-Token"]).to.equal("Test-Token");
|
||||
chai_1.expect(body["headers"]["Cookie"]).to.equal("test-cookie=cookie-value;");
|
||||
done();
|
||||
}).catch(function (e) {
|
||||
done(e);
|
||||
});
|
||||
});
|
||||
it("POST-Request", function (done) {
|
||||
var requestContext = new ts_petstore_client_1.RequestContext("http://httpbin.org/post", ts_petstore_client_1.HttpMethod.POST);
|
||||
requestContext.setHeaderParam("X-Test-Token", "Test-Token");
|
||||
requestContext.addCookie("test-cookie", "cookie-value");
|
||||
var formData = new FormData();
|
||||
formData.append("test", "test2");
|
||||
formData.append("testFile", Buffer.from("abc"), "fileName.json");
|
||||
requestContext.setBody(formData);
|
||||
lib.send(requestContext).then(function (resp) {
|
||||
chai_1.expect(resp.httpStatusCode, "Expected status code to be 200").to.eq(200);
|
||||
var body = JSON.parse(resp.body);
|
||||
chai_1.expect(body["headers"]).to.exist;
|
||||
chai_1.expect(body["headers"]["X-Test-Token"]).to.equal("Test-Token");
|
||||
chai_1.expect(body["headers"]["Cookie"]).to.equal("test-cookie=cookie-value;");
|
||||
chai_1.expect(body["files"]["testFile"]).to.equal("abc");
|
||||
chai_1.expect(body["form"]["test"]).to.equal("test2");
|
||||
done();
|
||||
}).catch(function (e) {
|
||||
done(e);
|
||||
});
|
||||
});
|
||||
it("Cookies-Request", function (done) {
|
||||
var requestContext = new ts_petstore_client_1.RequestContext("http://httpbin.org/cookies", ts_petstore_client_1.HttpMethod.GET);
|
||||
requestContext.addCookie("test-cookie", "cookie-value");
|
||||
lib.send(requestContext).then(function (resp) {
|
||||
chai_1.expect(resp.httpStatusCode, "Expected status code to be 200").to.eq(200);
|
||||
var body = JSON.parse(resp.body);
|
||||
chai_1.expect(body["cookies"]["test-cookie"]).to.equal("cookie-value");
|
||||
done();
|
||||
}).catch(function (e) {
|
||||
done(e);
|
||||
});
|
||||
});
|
||||
});
|
||||
};
|
||||
for (var libName in libs) {
|
||||
_loop_1(libName);
|
||||
}
|
@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
||||
var rewire = require("rewire");
|
||||
var chai_1 = require("chai");
|
||||
var ts_petstore_client_1 = require("ts-petstore-client");
|
||||
var objectSerializerFile = rewire("../../node_modules/ts-petstore-client/dist/models/ObjectSerializer.js");
|
||||
var objectSerializerFile = rewire(__dirname + "/../../node_modules/ts-petstore-client/models/ObjectSerializer.ts");
|
||||
var ObjectSerializer = objectSerializerFile.__get__("ObjectSerializer");
|
||||
describe("ObjectSerializer", function () {
|
||||
describe("Serialize", function () {
|
||||
|
@ -3,7 +3,7 @@ import { expect} from "chai";
|
||||
import {Pet, Category, Tag} from "ts-petstore-client"
|
||||
|
||||
|
||||
const objectSerializerFile = rewire("../../node_modules/ts-petstore-client/dist/models/ObjectSerializer.js")
|
||||
const objectSerializerFile = rewire(__dirname + "/../../node_modules/ts-petstore-client/models/ObjectSerializer.ts")
|
||||
|
||||
const ObjectSerializer = objectSerializerFile.__get__("ObjectSerializer")
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user