Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUGFIX] Fix test setup #48

Merged
merged 3 commits into from
Aug 4, 2022
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Ignore fields that are undefined in error check
  • Loading branch information
egmacke committed Aug 4, 2022
commit bc5f5887a2ad56d48ee618cb07bfb003c0421717
35 changes: 21 additions & 14 deletions src/models/error.model.ts
Original file line number Diff line number Diff line change
@@ -1,30 +1,37 @@
import { Dictionary, nullish } from '..';
import { ErrorOptions } from '../interfaces/error.interface';
import { isObject } from '../utils/is-object';
import Link from './link.model';
import Meta from './meta.model';
import { isObject } from '../utils/is-object';

export default class JapiError {
/**
* Tests whether `error` has similar attributes to a JapiError
*
* @param error - An unknown object
* @param error An unknown object
*/
public static isLikeJapiError(error: unknown): error is Partial<JapiError> {
console.log(!isObject(error));
if (!isObject(error)) return false;
return (
['id', 'status', 'code', 'title', 'detail', 'source', 'links', 'meta'].some(
(attrName) => attrName in error
) &&
[
(['id', 'status', 'code', 'title', 'detail'] as const).every(
(attrName) => !(attrName in error) || typeof error[attrName] === 'string'
),
(['source', 'links', 'meta'] as const).every(
(attrName) => !(attrName in error) || isObject(error[attrName])
),
].every((v) => v)
const hasErrorKeys = [
'id',
'status',
'code',
'title',
'detail',
'source',
'links',
'meta',
].some((attrName) => attrName in error);
const expectedStringKeys = (['id', 'status', 'code', 'title', 'detail'] as const).every(
(attrName) =>
!(attrName in error) || error[attrName] === undefined || typeof error[attrName] === 'string'
);
const expectedObjectKeys = (['source', 'links', 'meta'] as const).every(
(attrName) =>
!(attrName in error) || error[attrName] === undefined || isObject(error[attrName])
);
return hasErrorKeys && [expectedStringKeys, expectedObjectKeys].every((v) => v);
}

/** @internal */
Expand Down