-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2095 from sanger/develop
[release] Merge Develop into Master
- Loading branch information
Showing
39 changed files
with
772 additions
and
587 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
3.64.2 | ||
3.64.3 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
app/frontend/javascript/asset-comments/comment-store-helpers.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import devourApi from '@/javascript/shared/devourApi.js' | ||
import resources from '@/javascript/shared/resources.js' | ||
import axios from 'axios' | ||
import commentStoreFactory from '@/javascript/asset-comments/comment-store.js' | ||
|
||
const commentFactoryStores = {} | ||
|
||
const createCommentFactory = (props) => { | ||
let commentFactoryStoreForAsset = commentFactoryStores[props.assetId] | ||
if (commentFactoryStoreForAsset && commentFactoryStoreForAsset.commentFactory) { | ||
commentFactoryStoreForAsset.refCount++ | ||
return commentFactoryStoreForAsset.commentFactory | ||
} | ||
|
||
const sequencescapeApiUrl = props.sequencescapeApi | ||
const sequencescapeApiKey = props.sequencescapeApiKey | ||
const axiosInstance = axios.create({ | ||
baseURL: sequencescapeApiUrl, | ||
timeout: 10000, | ||
headers: { | ||
Accept: 'application/vnd.api+json', | ||
'Content-Type': 'application/vnd.api+json', | ||
}, | ||
}) | ||
const api = devourApi({ apiUrl: sequencescapeApiUrl }, resources, sequencescapeApiKey) | ||
const commentFactory = commentStoreFactory(axiosInstance, api, props.assetId, props.userId) | ||
|
||
commentFactoryStores[props.assetId] = { commentFactory, refCount: 1 } | ||
return commentFactory | ||
} | ||
|
||
const removeCommentFactory = (assetId) => { | ||
if (commentFactoryStores[assetId]) { | ||
commentFactoryStores[assetId].refCount -= 1 | ||
if (commentFactoryStores[assetId].refCount === 0) { | ||
delete commentFactoryStores[assetId] | ||
} | ||
} | ||
} | ||
|
||
export { createCommentFactory, removeCommentFactory, commentFactoryStores } |
102 changes: 102 additions & 0 deletions
102
app/frontend/javascript/asset-comments/comment-store-helpers.spec.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
import { | ||
createCommentFactory, | ||
removeCommentFactory, | ||
commentFactoryStores, | ||
} from '@/javascript/asset-comments/comment-store-helpers.js' | ||
import devourApi from '@/javascript/shared/devourApi.js' | ||
import resources from '@/javascript/shared/resources.js' | ||
import commentStoreFactory from '@/javascript/asset-comments/comment-store.js' | ||
import axios from 'axios' | ||
|
||
vi.mock('axios') | ||
vi.mock('@/javascript/shared/devourApi.js') | ||
vi.mock('@/javascript/asset-comments/comment-store.js') | ||
|
||
describe('commentFactory', () => { | ||
let mockAxiosInstance | ||
let mockDevourApi | ||
let mockCommentFactory | ||
|
||
beforeEach(() => { | ||
mockAxiosInstance = { | ||
create: vi.fn().mockReturnValue({ | ||
baseURL: 'http://example.com/api', | ||
timeout: 10000, | ||
headers: { | ||
Accept: 'application/vnd.api+json', | ||
'Content-Type': 'application/vnd.api+json', | ||
}, | ||
}), | ||
} | ||
axios.create.mockReturnValue(mockAxiosInstance) | ||
|
||
mockDevourApi = vi.fn() | ||
devourApi.mockReturnValue(mockDevourApi) | ||
|
||
mockCommentFactory = {} | ||
commentStoreFactory.mockReturnValue(mockCommentFactory) | ||
}) | ||
|
||
afterEach(() => { | ||
vi.clearAllMocks() | ||
}) | ||
|
||
it('creates a new commentFactory and stores it', () => { | ||
const props = { | ||
sequencescapeApi: 'http://example.com/api', | ||
sequencescapeApiKey: 'test-api-key', | ||
assetId: '123', | ||
userId: 'user_id', | ||
} | ||
|
||
const result = createCommentFactory(props) | ||
|
||
expect(axios.create).toHaveBeenCalledWith({ | ||
baseURL: props.sequencescapeApi, | ||
timeout: 10000, | ||
headers: { | ||
Accept: 'application/vnd.api+json', | ||
'Content-Type': 'application/vnd.api+json', | ||
}, | ||
}) | ||
expect(devourApi).toHaveBeenCalledWith({ apiUrl: props.sequencescapeApi }, resources, props.sequencescapeApiKey) | ||
expect(commentStoreFactory).toHaveBeenCalledWith(mockAxiosInstance, mockDevourApi, props.assetId, props.userId) | ||
expect(result).toBe(mockCommentFactory) | ||
expect(commentFactoryStores[props.assetId]).toEqual({ commentFactory: mockCommentFactory, refCount: 1 }) | ||
}) | ||
|
||
it('returns an existing commentFactory and increments the refCount', () => { | ||
const props = { | ||
sequencescapeApi: 'http://example.com/api', | ||
sequencescapeApiKey: 'test-api-key', | ||
assetId: '123', | ||
userId: 'user_id', | ||
} | ||
|
||
commentFactoryStores[props.assetId] = { commentFactory: mockCommentFactory, refCount: 1 } | ||
|
||
const result = createCommentFactory(props) | ||
|
||
expect(result).toBe(mockCommentFactory) | ||
expect(commentFactoryStores[props.assetId].refCount).toBe(2) | ||
expect(commentStoreFactory).not.toHaveBeenCalled() | ||
}) | ||
|
||
it('removes a commentFactory when refCount drops to zero', () => { | ||
const assetId = '123' | ||
commentFactoryStores[assetId] = { commentFactory: mockCommentFactory, refCount: 1 } | ||
|
||
removeCommentFactory(assetId) | ||
|
||
expect(commentFactoryStores[assetId]).toBeUndefined() | ||
}) | ||
|
||
it('decrements the refCount without removing the commentFactory', () => { | ||
const assetId = '123' | ||
commentFactoryStores[assetId] = { commentFactory: mockCommentFactory, refCount: 2 } | ||
|
||
removeCommentFactory(assetId) | ||
|
||
expect(commentFactoryStores[assetId].refCount).toBe(1) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.