Skip to content

Commit

Permalink
Lint story-custom-field.test.ts (#278)
Browse files Browse the repository at this point in the history
  • Loading branch information
JensAstrup authored Jun 4, 2024
1 parent 3cff7e3 commit 16fae7e
Showing 1 changed file with 10 additions and 11 deletions.
21 changes: 10 additions & 11 deletions tests/stories/custom-fields/story-custom-field.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,36 +5,35 @@ import StoryCustomFieldInterface from '@sx/stories/custom-fields/contracts/story
import StoryCustomField from '@sx/stories/custom-fields/story-custom-field'


jest.mock('../../../src/utils/headers', () => ({
getHeaders: jest.fn().mockReturnValue({Authorization: 'Bearer token'})
jest.mock('@sx/utils/headers', () => ({
getHeaders: jest.fn().mockReturnValue({ Authorization: 'Bearer token' })

Check failure

Code scanning / CodeQL

Hard-coded credentials Critical test

The hard-coded value "Bearer token" is used as
authorization header
.
}))


describe('Story Custom Field', () => {
it('should instantiate a new custom field', () => {
const customField = new StoryCustomField({fieldId: '1'} as StoryCustomFieldInterface)
const customField = new StoryCustomField({ fieldId: '1' } as StoryCustomFieldInterface)
expect(customField).toBeInstanceOf(StoryCustomField)
})

it('should return saved custom field', async () => {
const storyCustomField = new StoryCustomField({fieldId: '1'} as StoryCustomFieldInterface)
const customField: CustomField = new CustomField({id: '1'} as CustomFieldInterface)
const storyCustomField = new StoryCustomField({ fieldId: '1' } as StoryCustomFieldInterface)
const customField: CustomField = new CustomField({ id: '1' } as CustomFieldInterface)
const customFieldGet = jest.spyOn(CustomFieldsService.prototype, 'get').mockResolvedValue(customField)
const savedCustomField: CustomField = await storyCustomField.field
expect(savedCustomField).toBeInstanceOf(CustomField)
await expect(storyCustomField.field).resolves.toBeInstanceOf(CustomField)
expect(customFieldGet).toHaveBeenCalledTimes(1)

})

it('should return a field', async () => {
jest.spyOn(CustomFieldsService.prototype, 'get').mockResolvedValue(new CustomField({
id: '1',
values: [{fieldId: '1', value: 'value'} as unknown as CustomFieldInterface]
values: [{ fieldId: '1', value: 'value' } as unknown as CustomFieldInterface]
} as unknown as CustomFieldInterface))
const customStoryField: StoryCustomField = new StoryCustomField({fieldId: '1'} as StoryCustomFieldInterface)
const customStoryField: StoryCustomField = new StoryCustomField({ fieldId: '1' } as StoryCustomFieldInterface)
const customField: CustomField = await customStoryField.field
expect(customField.values).toEqual([{fieldId: '1', value: 'value'}])
expect(customField.values).toEqual([{ fieldId: '1', value: 'value' }])
expect(customField).toBeInstanceOf(CustomField)
})

Expand All @@ -45,9 +44,9 @@ describe('Story Custom Field', () => {
canonicalName: 'fieldName',
createdAt: new Date(),
description: 'description',
values: [{fieldId: '1', value: 'value'}]
values: [{ fieldId: '1', value: 'value' }]
} as unknown as CustomFieldInterface))
const customStoryField: StoryCustomField = new StoryCustomField({fieldId: '1'} as StoryCustomFieldInterface)
const customStoryField: StoryCustomField = new StoryCustomField({ fieldId: '1' } as StoryCustomFieldInterface)
const customFieldName: string = await customStoryField.name
expect(customFieldName).toEqual('field')
})
Expand Down

0 comments on commit 16fae7e

Please sign in to comment.