improve generated Service test template
See original GitHub issueThe current generated Service test is not actually testing the generated Service code (i.e. not even if it exists):
// api/src/services/posts/posts.test.js
/*
import { posts } from './posts'
*/
describe('posts', () => {
it('returns true', () => {
expect(true).toBe(true)
})
})
Given the recent MSW integration with test DB, could we update this to at least be meaningful?
And we do have two cases to consider if we’d like to handle both distinctly:
yarn rw g service post
(no CRUD)
// api/src/services/posts/posts.js
import { db } from 'src/lib/db'
export const posts = () => {
return db.post.findMany()
}
yarn rw g service post --crud
// api/src/services/posts/posts.js
import { db } from 'src/lib/db'
export const posts = () => {
return db.post.findMany()
}
export const post = ({ id }) => {
return db.post.findOne({
where: { id },
})
}
export const createPost = ({ input }) => {
return db.post.create({
data: input,
})
}
export const updatePost = ({ id, input }) => {
return db.post.update({
data: input,
where: { id },
})
}
export const deletePost = ({ id }) => {
return db.post.delete({
where: { id },
})
}
Issue Analytics
- State:
- Created 3 years ago
- Comments:10 (10 by maintainers)
Top Results From Across the Web
Test templates - Product Documentation | ServiceNow
The Test Templates module opens a list of available templates. From this module, you create, view, and edit test templates.
Read more >How To Write Test Strategy Document (With Sample Test ...
Process to Develop a Good Test Strategy Document. Don't just follow the templates without understanding what works best for your project.
Read more >Create a Web Service Test - Visual Studio (Windows)
In Visual Studio, create a new project using the ASP.NET Web Application (.NET Framework) template, and select the Empty template when prompted.
Read more >Free, Easy Test Maker—Create Multiple Choice Tests, Fast
The easy test maker that engages your colleagues, pupils, or friends. Use this test maker to create a multiple choice test or online...
Read more >How to Write Test Cases for Software: Examples & Tutorial
Writing excellent test cases is just one more way to enhance team ... However, the test case template would likely vary from company...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Worked on some stuff with @mojombo this afternoon and I’m recording this here for posterity… another possible way to define fixtures. Uses the target model as the root key in the object (
comment
) and then gives each fixture a name with the second level key:This would allow us to:
Maybe rather than referencing the FIXTURES directly we can create a
fixtures
function which will reference the fixture data after being added to the database so that we can access any fields that were created by defaults in the database:Oh snap, now we’re on to something…
IT’S HAPPENING https://github.com/redwoodjs/redwood/pull/1465