Skip to content

Commit

Permalink
Clean up some add project endpoint tests
Browse files Browse the repository at this point in the history
  • Loading branch information
EvanHahn committed Oct 17, 2024
1 parent 32e403c commit 74fd08a
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 5 deletions.
28 changes: 28 additions & 0 deletions src/lib/omit.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/**
* Returns a new object with the own enumerable keys of `obj` that are not in `keys`.
*
* In other words, remove some keys from an object.
*
* @template {object} T
* @template {keyof T} K
* @param {T} obj
* @param {ReadonlyArray<K>} keys
* @returns {Omit<T, K>}
* @example
* const obj = { foo: 1, bar: 2, baz: 3 }
* omit(obj, ['foo', 'bar'])
* // => { baz: 3 }
*/
export function omit(obj, keys) {
/** @type {Partial<T>} */ const result = {}

/** @type {Set<unknown>} */ const toOmit = new Set(keys)

for (const key in obj) {
if (!Object.hasOwn(obj, key)) continue
if (toOmit.has(key)) continue
result[key] = obj[key]
}

return /** @type {Omit<T, K>} */ (result)
}
30 changes: 25 additions & 5 deletions test-e2e/server/add-project-endpoint.js
Original file line number Diff line number Diff line change
@@ -1,27 +1,47 @@
import assert from 'node:assert/strict'
import test from 'node:test'
import { createTestServer, randomProjectKeys } from './test-helpers.js'
import { omit } from '../../src/lib/omit.js'
import { projectKeyToPublicId } from '../../src/utils.js'
import { createTestServer, randomProjectKeys } from './test-helpers.js'

test('request missing project key', async (t) => {
const server = createTestServer(t)

const response = await server.inject({
method: 'POST',
url: '/projects',
// TODO: omit the project key
body: randomProjectKeys(),
body: omit(randomProjectKeys(), ['projectKey']),
})

assert.equal(response.statusCode, 400)
})

test('request missing any encryption keys', async (t) => {
// TODO
const server = createTestServer(t)

const response = await server.inject({
method: 'POST',
url: '/projects',
body: omit(randomProjectKeys(), ['encryptionKeys']),
})

assert.equal(response.statusCode, 400)
})

test('request missing an encryption key', async (t) => {
// TODO
const server = createTestServer(t)
const projectKeys = randomProjectKeys()

const response = await server.inject({
method: 'POST',
url: '/projects',
body: {
...projectKeys,
encryptionKeys: omit(projectKeys.encryptionKeys, ['config']),
},
})

assert.equal(response.statusCode, 400)
})

test('adding a project', async (t) => {
Expand Down

0 comments on commit 74fd08a

Please sign in to comment.