mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-08 14:35:45 +01:00
migrate ui-components from flow to typescript
This commit is contained in:
@@ -1,31 +1,31 @@
|
||||
import { apiClient, createUrl } from './apiclient';
|
||||
import fetchMock from 'fetch-mock';
|
||||
import { BackendError } from './errors';
|
||||
import { apiClient, createUrl } from "./apiclient";
|
||||
import fetchMock from "fetch-mock";
|
||||
import { BackendError } from "./errors";
|
||||
|
||||
describe('create url', () => {
|
||||
it('should not change absolute urls', () => {
|
||||
expect(createUrl('https://www.scm-manager.org')).toBe(
|
||||
'https://www.scm-manager.org',
|
||||
describe("create url", () => {
|
||||
it("should not change absolute urls", () => {
|
||||
expect(createUrl("https://www.scm-manager.org")).toBe(
|
||||
"https://www.scm-manager.org"
|
||||
);
|
||||
});
|
||||
|
||||
it('should add prefix for api', () => {
|
||||
expect(createUrl('/users')).toBe('/api/v2/users');
|
||||
expect(createUrl('users')).toBe('/api/v2/users');
|
||||
it("should add prefix for api", () => {
|
||||
expect(createUrl("/users")).toBe("/api/v2/users");
|
||||
expect(createUrl("users")).toBe("/api/v2/users");
|
||||
});
|
||||
});
|
||||
|
||||
describe('error handling tests', () => {
|
||||
describe("error handling tests", () => {
|
||||
const earthNotFoundError = {
|
||||
transactionId: '42t',
|
||||
errorCode: '42e',
|
||||
message: 'earth not found',
|
||||
transactionId: "42t",
|
||||
errorCode: "42e",
|
||||
message: "earth not found",
|
||||
context: [
|
||||
{
|
||||
type: 'planet',
|
||||
id: 'earth',
|
||||
},
|
||||
],
|
||||
type: "planet",
|
||||
id: "earth"
|
||||
}
|
||||
]
|
||||
};
|
||||
|
||||
afterEach(() => {
|
||||
@@ -33,40 +33,40 @@ describe('error handling tests', () => {
|
||||
fetchMock.restore();
|
||||
});
|
||||
|
||||
it('should create a normal error, if the content type is not scmm-error', done => {
|
||||
fetchMock.getOnce('/api/v2/error', {
|
||||
status: 404,
|
||||
it("should create a normal error, if the content type is not scmm-error", done => {
|
||||
fetchMock.getOnce("/api/v2/error", {
|
||||
status: 404
|
||||
});
|
||||
|
||||
apiClient.get('/error').catch((err: Error) => {
|
||||
expect(err.name).toEqual('Error');
|
||||
expect(err.message).toContain('404');
|
||||
apiClient.get("/error").catch((err: Error) => {
|
||||
expect(err.name).toEqual("Error");
|
||||
expect(err.message).toContain("404");
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should create an backend error, if the content type is scmm-error', done => {
|
||||
fetchMock.getOnce('/api/v2/error', {
|
||||
it("should create an backend error, if the content type is scmm-error", done => {
|
||||
fetchMock.getOnce("/api/v2/error", {
|
||||
status: 404,
|
||||
headers: {
|
||||
'Content-Type': 'application/vnd.scmm-error+json;v=2',
|
||||
"Content-Type": "application/vnd.scmm-error+json;v=2"
|
||||
},
|
||||
body: earthNotFoundError,
|
||||
body: earthNotFoundError
|
||||
});
|
||||
|
||||
apiClient.get('/error').catch((err: BackendError) => {
|
||||
apiClient.get("/error").catch((err: BackendError) => {
|
||||
expect(err).toBeInstanceOf(BackendError);
|
||||
|
||||
expect(err.message).toEqual('earth not found');
|
||||
expect(err.message).toEqual("earth not found");
|
||||
expect(err.statusCode).toBe(404);
|
||||
|
||||
expect(err.transactionId).toEqual('42t');
|
||||
expect(err.errorCode).toEqual('42e');
|
||||
expect(err.transactionId).toEqual("42t");
|
||||
expect(err.errorCode).toEqual("42e");
|
||||
expect(err.context).toEqual([
|
||||
{
|
||||
type: 'planet',
|
||||
id: 'earth',
|
||||
},
|
||||
type: "planet",
|
||||
id: "earth"
|
||||
}
|
||||
]);
|
||||
done();
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user