Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/api/test/__fixtures__/sdk/alby/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class SDK {

constructor() {
this.spec = Oas.init(definition);
this.core = new APICore(this.spec, 'alby/1.0.14 (api/5.0-unit-testing)');
this.core = new APICore(this.spec, 'alby/1.0.14 (api/<<package version>>)');
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class SDK {

constructor() {
this.spec = Oas.init(definition);
this.core = new APICore(this.spec, 'operationid-quirks/1.0.0 (api/5.0-unit-testing)');
this.core = new APICore(this.spec, 'operationid-quirks/1.0.0 (api/<<package version>>)');
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class SDK {

constructor() {
this.spec = Oas.init(definition);
this.core = new APICore(this.spec, 'optional-payload/1.0.0 (api/5.0-unit-testing)');
this.core = new APICore(this.spec, 'optional-payload/1.0.0 (api/<<package version>>)');
}

/**
Expand Down
2 changes: 1 addition & 1 deletion packages/api/test/__fixtures__/sdk/petstore/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class SDK {

constructor() {
this.spec = Oas.init(definition);
this.core = new APICore(this.spec, 'petstore/1.0.0 (api/5.0-unit-testing)');
this.core = new APICore(this.spec, 'petstore/1.0.0 (api/<<package version>>)');
}

/**
Expand Down
2 changes: 1 addition & 1 deletion packages/api/test/__fixtures__/sdk/readme/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class SDK {

constructor() {
this.spec = Oas.init(definition);
this.core = new APICore(this.spec, 'readme/2.0.0 (api/5.0-unit-testing)');
this.core = new APICore(this.spec, 'readme/2.0.0 (api/<<package version>>)');
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class SDK {

constructor() {
this.spec = Oas.init(definition);
this.core = new APICore(this.spec, 'response-title-quirks/1.0.0 (api/5.0-unit-testing)');
this.core = new APICore(this.spec, 'response-title-quirks/1.0.0 (api/<<package version>>)');
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ var simple_json_1 = __importDefault(require('../../../__fixtures__/definitions/s
var SDK = /** @class */ (function () {
function SDK() {
this.spec = oas_1.default.init(simple_json_1.default);
this.core = new core_1.default(this.spec, 'simple-js-cjs/1.0.0 (api/5.0-unit-testing)');
this.core = new core_1.default(this.spec, 'simple-js-cjs/1.0.0 (api/<<package version>>)');
}
/**
* Optionally configure various options that the SDK allows.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import definition from '../../../__fixtures__/definitions/simple.json';
class SDK {
constructor() {
this.spec = Oas.init(definition);
this.core = new APICore(this.spec, 'simple-js-esm/1.0.0 (api/5.0-unit-testing)');
this.core = new APICore(this.spec, 'simple-js-esm/1.0.0 (api/<<package version>>)');
}
/**
* Optionally configure various options that the SDK allows.
Expand Down
2 changes: 1 addition & 1 deletion packages/api/test/__fixtures__/sdk/simple-ts/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class SDK {

constructor() {
this.spec = Oas.init(definition);
this.core = new APICore(this.spec, 'simple-ts/1.0.0 (api/5.0-unit-testing)');
this.core = new APICore(this.spec, 'simple-ts/1.0.0 (api/<<package version>>)');
}

/**
Expand Down
12 changes: 0 additions & 12 deletions packages/api/test/cli/codegen/languages/typescript.test.ts
Original file line number Diff line number Diff line change
@@ -1,27 +1,15 @@
/* eslint-disable import/first */
import type { TSGeneratorOptions } from '../../../../src/cli/codegen/languages/typescript';

import { promises as fs } from 'fs';
import path from 'path';

import chai, { assert, expect } from 'chai';
import fetchMock from 'fetch-mock';
import mockRequire from 'mock-require';
import Oas from 'oas';
import sinon from 'sinon';
import sinonChai from 'sinon-chai';
import uniqueTempDir from 'unique-temp-dir';

// Because `packageInfo` is generated at build time and we're using it in tests, everytime we build
// a new release our tests will also need to get updated because we use `PACKAGE_VERSION` in user
// agent strings. Because nobody wants to have to fix broken tests everytime we build a new release
// we need to overload the `packageInfo` import here with some fake data that we can then use in our
// test snapshots.
mockRequire('../../../../src/packageInfo', {
PACKAGE_NAME: 'api',
PACKAGE_VERSION: '5.0-unit-testing',
});

import TSGenerator from '../../../../src/cli/codegen/languages/typescript';
import Storage from '../../../../src/cli/storage';
import chaiPlugins from '../../../helpers/chai-plugins';
Expand Down
16 changes: 13 additions & 3 deletions packages/api/test/helpers/chai-plugins.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import path from 'path';
import caseless from 'caseless';
import chai from 'chai';

import * as packageInfo from '../../src/packageInfo';

declare global {
// eslint-disable-next-line @typescript-eslint/no-namespace
namespace Chai {
Expand Down Expand Up @@ -40,7 +42,7 @@ export default function chaiPlugins(_chai, utils) {
const userAgent = this._obj['user-agent'];

this.assert(
userAgent.match(/api \(node\)\/\d+.\d+.\d+/),
userAgent.match(/^api \(node\)\/(\d+.\d+(.\d+|unit-testing))$/),
`expected "${userAgent}" to be a custom user agent`,
`expected "${userAgent}" to not be a custom user agent`
);
Expand Down Expand Up @@ -77,8 +79,16 @@ export default function chaiPlugins(_chai, utils) {

// Assert that each generated file is the same as in the fixture.
expectedFiles.forEach(file => {
const expected = fs.readFileSync(path.join(dir, file), 'utf8');
new chai.Assertion(actualFiles[file], `${file} does not match`).to.equal(expected);
const actual = actualFiles[file];

// We have to wrap in our current package version into the `<<useragent>>` placeholder so we
// don't need to worry about committing package versions into source control or trying to mock
// out our `packageInfo` library, potentially causing sideeffects in other tests.
const expected = fs
.readFileSync(path.join(dir, file), 'utf8')
.replace('<<package version>>', packageInfo.PACKAGE_VERSION);

new chai.Assertion(actual, `${file} does not match`).to.equal(expected);
});
});

Expand Down
2 changes: 1 addition & 1 deletion packages/api/test/integration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ describe('integration tests', function () {
expect(data.uri).to.equal('/anything/v1/oa_citations/records');
expect(data.requestBody).to.equal('criteria=propertyName%3Avalue');
expect(data.headers).to.have.deep.property('content-type', 'application/x-www-form-urlencoded');
expect(data.headers).to.have.a.customUserAgent;
expect(data.headers).to.have.be.a.customUserAgent;
});

// it.skip('should send along required parameters if not supplied', async function () {
Expand Down