This technically lets the cypress tests pass

@appinteractive when I run the whole apollo request in `asyncData` I get
errors that there is a mismatch of the virtual DOM trees for client and
server. Any ideas?
This commit is contained in:
Robert Schäfer 2019-02-28 02:49:54 +01:00
parent 804cb796b8
commit eaa2017ba4
3 changed files with 25 additions and 5 deletions

View File

@ -223,6 +223,11 @@ Then('the first post on the landing page has the title:', title => {
cy.get('.post-card:first').should('contain', title)
})
Then('I see a 404 error with the following message:', message => {
Then(
'the page {string} returns a 404 error with a message:',
(route, message) => {
// TODO: how can we check HTTP codes with cypress?
cy.visit(route, { failOnStatusCode: false })
cy.get('.error').should('contain', message)
})
}
)

View File

@ -20,8 +20,7 @@ Feature: Hide Posts
Scenario: Visiting a disabled post's page should return 404
Given I am logged in with a "user" role
When I visit the "/post/this-post-is-disabled" page
Then I see a 404 error with the following message:
Then the page "/post/this-post-is-disabled" returns a 404 error with a message:
"""
We cannot find that post :(
"""

View File

@ -162,6 +162,22 @@ export default {
this.title = this.post.title
}
},
async asyncData(context) {
const {
params,
error,
app: { apolloProvider }
} = context
const client = apolloProvider.defaultClient
const query = gql('query Post($slug: String!) { Post(slug: $slug) { id } }')
const variables = { slug: params.slug }
const {
data: { Post }
} = await client.query({ query, variables })
if (Post.length <= 0) {
error({ statusCode: 404, message: 'We cannot find that post :(' })
}
},
methods: {
isAuthor(id) {
return this.$store.getters['auth/user'].id === id