Skip to content

Commit

Permalink
Server: PUT /projects, not POST /projects
Browse files Browse the repository at this point in the history
  • Loading branch information
EvanHahn committed Oct 23, 2024
1 parent cf02e69 commit 4a42410
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 20 deletions.
2 changes: 1 addition & 1 deletion src/member-api.js
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ export class MemberApi extends TypedEmitter {
/** @type {Response} */ let response
try {
response = await fetch(requestUrl, {
method: 'POST',
method: 'PUT',
body: JSON.stringify(requestBody),
headers: { 'Content-Type': 'application/json' },
})
Expand Down
2 changes: 1 addition & 1 deletion src/server/routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ export default async function routes(
}
)

fastify.post(
fastify.put(
'/projects',
{
schema: {
Expand Down
24 changes: 12 additions & 12 deletions src/server/test/add-project-endpoint.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ test('request missing project key', async (t) => {
const server = createTestServer(t)

const response = await server.inject({
method: 'POST',
method: 'PUT',
url: '/projects',
body: omit(randomProjectKeys(), ['projectKey']),
})
Expand All @@ -20,7 +20,7 @@ test('request missing any encryption keys', async (t) => {
const server = createTestServer(t)

const response = await server.inject({
method: 'POST',
method: 'PUT',
url: '/projects',
body: omit(randomProjectKeys(), ['encryptionKeys']),
})
Expand All @@ -33,7 +33,7 @@ test('request missing an encryption key', async (t) => {
const projectKeys = randomProjectKeys()

const response = await server.inject({
method: 'POST',
method: 'PUT',
url: '/projects',
body: {
...projectKeys,
Expand All @@ -48,7 +48,7 @@ test('adding a project', async (t) => {
const server = createTestServer(t)

const response = await server.inject({
method: 'POST',
method: 'PUT',
url: '/projects',
body: randomProjectKeys(),
})
Expand All @@ -63,14 +63,14 @@ test('adding a second project fails by default', async (t) => {
const server = createTestServer(t)

const firstAddResponse = await server.inject({
method: 'POST',
method: 'PUT',
url: '/projects',
body: randomProjectKeys(),
})
assert.equal(firstAddResponse.statusCode, 200)

const response = await server.inject({
method: 'POST',
method: 'PUT',
url: '/projects',
body: randomProjectKeys(),
})
Expand All @@ -84,7 +84,7 @@ test('allowing a maximum number of projects', async (t) => {
await t.test('adding 3 projects', async () => {
for (let i = 0; i < 3; i++) {
const response = await server.inject({
method: 'POST',
method: 'PUT',
url: '/projects',
body: randomProjectKeys(),
})
Expand All @@ -94,7 +94,7 @@ test('allowing a maximum number of projects', async (t) => {

await t.test('attempting to add 4th project fails', async () => {
const response = await server.inject({
method: 'POST',
method: 'PUT',
url: '/projects',
body: randomProjectKeys(),
})
Expand All @@ -117,7 +117,7 @@ test(

await t.test('adding a project in the list', async () => {
const response = await server.inject({
method: 'POST',
method: 'PUT',
url: '/projects',
body: projectKeys,
})
Expand All @@ -126,7 +126,7 @@ test(

await t.test('trying to add a project not in the list', async () => {
const response = await server.inject({
method: 'POST',
method: 'PUT',
url: '/projects',
body: randomProjectKeys(),
})
Expand All @@ -140,14 +140,14 @@ test('adding the same project twice is idempotent', async (t) => {
const projectKeys = randomProjectKeys()

const firstResponse = await server.inject({
method: 'POST',
method: 'PUT',
url: '/projects',
body: projectKeys,
})
assert.equal(firstResponse.statusCode, 200)

const secondResponse = await server.inject({
method: 'POST',
method: 'PUT',
url: '/projects',
body: projectKeys,
})
Expand Down
2 changes: 1 addition & 1 deletion src/server/test/list-projects-endpoint.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ test('listing projects', async (t) => {
await Promise.all(
[projectKeys1, projectKeys2].map(async (projectKeys) => {
const response = await server.inject({
method: 'POST',
method: 'PUT',
url: '/projects',
body: projectKeys,
})
Expand Down
2 changes: 1 addition & 1 deletion src/server/test/observations-endpoint.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ test('returning no observations', async (t) => {
)

const addProjectResponse = await server.inject({
method: 'POST',
method: 'PUT',
url: '/projects',
body: projectKeys,
})
Expand Down
2 changes: 1 addition & 1 deletion src/server/test/sync-endpoint.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ test('sync endpoint is available after adding a project', async (t) => {
})

await server.inject({
method: 'POST',
method: 'PUT',
url: '/projects',
body: projectKeys,
})
Expand Down
6 changes: 3 additions & 3 deletions test-e2e/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ test(
[204, 302, 400, 500].map((statusCode) =>
t.test(`when returning a ${statusCode}`, async (t) => {
const fastify = createFastify()
fastify.post('/projects', (_req, reply) => {
fastify.put('/projects', (_req, reply) => {
reply.status(statusCode).send()
})
const serverBaseUrl = await fastify.listen()
Expand Down Expand Up @@ -142,7 +142,7 @@ test(
].map((responseData) =>
t.test(`when returning ${responseData}`, async (t) => {
const fastify = createFastify()
fastify.post('/projects', (_req, reply) => {
fastify.put('/projects', (_req, reply) => {
reply.header('Content-Type', 'application/json').send(responseData)
})
const serverBaseUrl = await fastify.listen()
Expand Down Expand Up @@ -171,7 +171,7 @@ test("fails if first request succeeds but sync doesn't", async (t) => {
const project = await manager.getProject(projectId)

const fastify = createFastify()
fastify.post('/projects', (_req, reply) => {
fastify.put('/projects', (_req, reply) => {
reply.send({ data: { deviceId: 'abc123' } })
})
const serverBaseUrl = await fastify.listen()
Expand Down

0 comments on commit 4a42410

Please sign in to comment.