-
Notifications
You must be signed in to change notification settings - Fork 5
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
Feature: project templates service #516
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { api } from 'boot/axios'; | ||
import { getTemplatesByType } from 'src/composables/TemplateManager'; | ||
|
||
/** | ||
* Filter and return only API templates related to a provided type. | ||
* @param {string} type - Type of template you want to get. PROJECT | COMPONENT | MODEL | ||
* @returns {Promise<object>} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. rework on documentation. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. PROJECT | COMPONENT | MODEL -> |
||
* otherwise an error. | ||
*/ | ||
export async function getAPITemplatesByType(type) { | ||
return api.get(`/libraries/templates?type=${type}`).then((data) => data.content); | ||
} | ||
|
||
/** | ||
* Get "project" templates. | ||
* @returns {Array} return array of project templates. | ||
*/ | ||
export async function getProjectTemplates() { | ||
if (!process.env.HAS_BACKEND) { | ||
return getTemplatesByType('project'); | ||
} | ||
|
||
return getAPITemplatesByType('PROJECT'); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import { api } from 'src/boot/axios'; | ||
import * as TemplatesService from 'src/services/TemplatesService'; | ||
import { getTemplatesByType } from 'src/composables/TemplateManager'; | ||
|
||
jest.mock('src/boot/axios', () => ({ | ||
api: { | ||
get: jest.fn(), | ||
}, | ||
})); | ||
|
||
jest.mock('src/composables/TemplateManager', () => ({ | ||
getTemplatesByType: jest.fn(), | ||
})); | ||
|
||
describe('Templates Service', () => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think is no like other test file, please check it There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I dont understand. I just did like in User Service tests file |
||
describe('Test function: getApiTemplatesByType', () => { | ||
it('should return a template list', async () => { | ||
const resultGetTemplates = { content: [{ name: 'Project Template', type: 'PROJECT' }] }; | ||
api.get.mockImplementation(() => Promise.resolve(resultGetTemplates)); | ||
|
||
const res = await TemplatesService.getAPITemplatesByType('project'); | ||
|
||
expect(res.length).toEqual(1); | ||
expect(res[0].name).toEqual('Project Template'); | ||
expect(res[0].type).toEqual('PROJECT'); | ||
}); | ||
}); | ||
|
||
describe('Test function: getProjectTemplates', () => { | ||
it('should return a template list without calling api', async () => { | ||
delete process.env.HAS_BACKEND; | ||
const resultGetTemplates = ['test']; | ||
getTemplatesByType.mockImplementation(() => Promise.resolve(resultGetTemplates)); | ||
|
||
const res = await TemplatesService.getProjectTemplates(); | ||
|
||
expect(res).toEqual(resultGetTemplates); | ||
}); | ||
|
||
it('should return a template list calling api', async () => { | ||
process.env.HAS_BACKEND = true; | ||
const resultGetTemplates = { content: [{ name: 'Project Template', type: 'PROJECT' }] }; | ||
api.get.mockImplementation(() => Promise.resolve(resultGetTemplates)); | ||
|
||
const res = await TemplatesService.getProjectTemplates(); | ||
|
||
expect(res.length).toEqual(1); | ||
expect(res[0].name).toEqual('Project Template'); | ||
expect(res[0].type).toEqual('PROJECT'); | ||
delete process.env.HAS_BACKEND; | ||
}); | ||
}); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
template name is a required string, no need
|| X
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When HAS_BACKEND is false the data have actually no
name
field