Skip to content

Commit

Permalink
add post note test 201
Browse files Browse the repository at this point in the history
  • Loading branch information
tryb3l committed Aug 27, 2024
1 parent d394b0d commit 83a5431
Showing 1 changed file with 45 additions and 0 deletions.
45 changes: 45 additions & 0 deletions test/notes/POST/post-note.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
'use strict'

const t = require('tap')
const { setup } = require('../../utils/setup-user')
const { randomString } = require('../../utils/data-creator')

t.beforeEach(async (t) => {
const { app, accessToken, refreshToken } = await setup(t)
t.context.app = app
t.context.accessToken = accessToken
t.context.refreshToken = refreshToken
})

const noteTitle = randomString(10)
const noteBody = randomString(20)
const noteTags = [randomString(5)]

t.test('POST /notes 201', async (t) => {
// Arrange
const { app, accessToken, refreshToken } = t.context

// Act
const response = await app.inject({
method: 'POST',
url: '/notes/',
headers: {
contentType: 'application/json',
},
cookies: {
accessToken: accessToken,
refreshToken: refreshToken,
},
payload: {
title: noteTitle,
body: noteBody,
tags: noteTags,
},
})

// Assert
t.equal(response.statusCode, 201)
t.type(response.json(), 'object')
t.ok(response.json().id)
t.equal(typeof response.json().id, 'string')
})

0 comments on commit 83a5431

Please sign in to comment.