diff --git a/Meadowlark-js/backends/meadowlark-elasticsearch-backend/package.json b/Meadowlark-js/backends/meadowlark-elasticsearch-backend/package.json index a54c74ff..7098889c 100644 --- a/Meadowlark-js/backends/meadowlark-elasticsearch-backend/package.json +++ b/Meadowlark-js/backends/meadowlark-elasticsearch-backend/package.json @@ -1,7 +1,7 @@ { "name": "@edfi/meadowlark-elasticsearch-backend", "main": "dist/index.js", - "version": "0.4.1-pre.0", + "version": "0.4.1-pre.1", "description": "Meadowlark backend plugin for elasticsearch", "license": "Apache-2.0", "publishConfig": { @@ -19,8 +19,8 @@ "build:copy-non-ts": "copyfiles -u 1 -e \"**/*.ts\" \"src/**/*\" dist --verbose" }, "dependencies": { - "@edfi/meadowlark-core": "0.4.1-pre.0", - "@edfi/meadowlark-utilities": "0.4.1-pre.0", + "@edfi/meadowlark-core": "0.4.1-pre.1", + "@edfi/meadowlark-utilities": "0.4.1-pre.1", "@elastic/elasticsearch": "^8.10.0", "@elastic/transport": "^8.3.4" }, diff --git a/Meadowlark-js/backends/meadowlark-mongodb-backend/package.json b/Meadowlark-js/backends/meadowlark-mongodb-backend/package.json index d5c9f63a..ff1c83de 100644 --- a/Meadowlark-js/backends/meadowlark-mongodb-backend/package.json +++ b/Meadowlark-js/backends/meadowlark-mongodb-backend/package.json @@ -1,7 +1,7 @@ { "name": "@edfi/meadowlark-mongodb-backend", "main": "dist/index.js", - "version": "0.4.1-pre.0", + "version": "0.4.1-pre.1", "description": "Meadowlark backend plugin for MongoDB", "license": "Apache-2.0", "publishConfig": { @@ -19,9 +19,9 @@ "build:copy-non-ts": "copyfiles -u 1 -e \"**/*.ts\" \"src/**/*\" dist --verbose" }, "dependencies": { - "@edfi/meadowlark-authz-server": "0.4.1-pre.0", - "@edfi/meadowlark-core": "0.4.1-pre.0", - "@edfi/meadowlark-utilities": "0.4.1-pre.0", + "@edfi/meadowlark-authz-server": "0.4.1-pre.1", + "@edfi/meadowlark-core": "0.4.1-pre.1", + "@edfi/meadowlark-utilities": "0.4.1-pre.1", "async-retry": "^1.3.3", "mongodb": "^5.9.2", "ramda": "0.29.1" diff --git a/Meadowlark-js/backends/meadowlark-opensearch-backend/package.json b/Meadowlark-js/backends/meadowlark-opensearch-backend/package.json index d8afc0e2..aeb44f13 100644 --- a/Meadowlark-js/backends/meadowlark-opensearch-backend/package.json +++ b/Meadowlark-js/backends/meadowlark-opensearch-backend/package.json @@ -1,7 +1,7 @@ { "name": "@edfi/meadowlark-opensearch-backend", "main": "dist/index.js", - "version": "0.4.1-pre.0", + "version": "0.4.1-pre.1", "description": "Meadowlark backend plugin for OpenSearch", "license": "Apache-2.0", "publishConfig": { @@ -19,8 +19,8 @@ "build:copy-non-ts": "copyfiles -u 1 -e \"**/*.ts\" \"src/**/*\" dist --verbose" }, "dependencies": { - "@edfi/meadowlark-core": "0.4.1-pre.0", - "@edfi/meadowlark-utilities": "0.4.1-pre.0", + "@edfi/meadowlark-core": "0.4.1-pre.1", + "@edfi/meadowlark-utilities": "0.4.1-pre.1", "@opensearch-project/opensearch": "^2.4.0" }, "devDependencies": { diff --git a/Meadowlark-js/backends/meadowlark-postgresql-backend/package.json b/Meadowlark-js/backends/meadowlark-postgresql-backend/package.json index ef5d20d8..4552133d 100644 --- a/Meadowlark-js/backends/meadowlark-postgresql-backend/package.json +++ b/Meadowlark-js/backends/meadowlark-postgresql-backend/package.json @@ -1,7 +1,7 @@ { "name": "@edfi/meadowlark-postgresql-backend", "main": "dist/index.js", - "version": "0.4.1-pre.0", + "version": "0.4.1-pre.1", "description": "Meadowlark backend plugin for PostgreSQL", "license": "Apache-2.0", "publishConfig": { @@ -19,9 +19,9 @@ "build:copy-non-ts": "copyfiles -u 1 -e \"**/*.ts\" \"src/**/*\" dist --verbose" }, "dependencies": { - "@edfi/meadowlark-authz-server": "0.4.1-pre.0", - "@edfi/meadowlark-core": "0.4.1-pre.0", - "@edfi/meadowlark-utilities": "0.4.1-pre.0", + "@edfi/meadowlark-authz-server": "0.4.1-pre.1", + "@edfi/meadowlark-core": "0.4.1-pre.1", + "@edfi/meadowlark-utilities": "0.4.1-pre.1", "pg": "^8.11.3", "pg-format": "^1.0.4", "ramda": "0.29.1" diff --git a/Meadowlark-js/lerna.json b/Meadowlark-js/lerna.json index bd91b3d1..58b0eebf 100644 --- a/Meadowlark-js/lerna.json +++ b/Meadowlark-js/lerna.json @@ -3,7 +3,7 @@ "packages": [ "packages/*" ], - "version": "0.4.1-pre.0", + "version": "0.4.1-pre.1", "npmClient": "npm", "useWorkspaces": true } diff --git a/Meadowlark-js/package-lock.json b/Meadowlark-js/package-lock.json index 4accdf9f..10a9f33c 100644 --- a/Meadowlark-js/package-lock.json +++ b/Meadowlark-js/package-lock.json @@ -52,11 +52,11 @@ }, "backends/meadowlark-elasticsearch-backend": { "name": "@edfi/meadowlark-elasticsearch-backend", - "version": "0.4.1-pre.0", + "version": "0.4.1-pre.1", "license": "Apache-2.0", "dependencies": { - "@edfi/meadowlark-core": "0.4.1-pre.0", - "@edfi/meadowlark-utilities": "0.4.1-pre.0", + "@edfi/meadowlark-core": "0.4.1-pre.1", + "@edfi/meadowlark-utilities": "0.4.1-pre.1", "@elastic/elasticsearch": "^8.10.0", "@elastic/transport": "^8.3.4" }, @@ -70,12 +70,12 @@ }, "backends/meadowlark-mongodb-backend": { "name": "@edfi/meadowlark-mongodb-backend", - "version": "0.4.1-pre.0", + "version": "0.4.1-pre.1", "license": "Apache-2.0", "dependencies": { - "@edfi/meadowlark-authz-server": "0.4.1-pre.0", - "@edfi/meadowlark-core": "0.4.1-pre.0", - "@edfi/meadowlark-utilities": "0.4.1-pre.0", + "@edfi/meadowlark-authz-server": "0.4.1-pre.1", + "@edfi/meadowlark-core": "0.4.1-pre.1", + "@edfi/meadowlark-utilities": "0.4.1-pre.1", "async-retry": "^1.3.3", "mongodb": "^5.9.2", "ramda": "0.29.1" @@ -88,11 +88,11 @@ }, "backends/meadowlark-opensearch-backend": { "name": "@edfi/meadowlark-opensearch-backend", - "version": "0.4.1-pre.0", + "version": "0.4.1-pre.1", "license": "Apache-2.0", "dependencies": { - "@edfi/meadowlark-core": "0.4.1-pre.0", - "@edfi/meadowlark-utilities": "0.4.1-pre.0", + "@edfi/meadowlark-core": "0.4.1-pre.1", + "@edfi/meadowlark-utilities": "0.4.1-pre.1", "@opensearch-project/opensearch": "^2.4.0" }, "devDependencies": { @@ -105,12 +105,12 @@ }, "backends/meadowlark-postgresql-backend": { "name": "@edfi/meadowlark-postgresql-backend", - "version": "0.4.1-pre.0", + "version": "0.4.1-pre.1", "license": "Apache-2.0", "dependencies": { - "@edfi/meadowlark-authz-server": "0.4.1-pre.0", - "@edfi/meadowlark-core": "0.4.1-pre.0", - "@edfi/meadowlark-utilities": "0.4.1-pre.0", + "@edfi/meadowlark-authz-server": "0.4.1-pre.1", + "@edfi/meadowlark-core": "0.4.1-pre.1", + "@edfi/meadowlark-utilities": "0.4.1-pre.1", "pg": "^8.11.3", "pg-format": "^1.0.4", "ramda": "0.29.1" @@ -22595,11 +22595,11 @@ }, "packages/meadowlark-authz-server": { "name": "@edfi/meadowlark-authz-server", - "version": "0.4.1-pre.0", + "version": "0.4.1-pre.1", "license": "Apache-2.0", "dependencies": { "@apideck/better-ajv-errors": "^0.3.6", - "@edfi/meadowlark-utilities": "0.4.1-pre.0", + "@edfi/meadowlark-utilities": "0.4.1-pre.1", "ajv": "^8.12.0", "didyoumean2": "^6.0.1", "dotenv": "^16.3.1", @@ -22649,11 +22649,11 @@ }, "packages/meadowlark-core": { "name": "@edfi/meadowlark-core", - "version": "0.4.1-pre.0", + "version": "0.4.1-pre.1", "license": "Apache-2.0", "dependencies": { "@apideck/better-ajv-errors": "^0.3.6", - "@edfi/meadowlark-utilities": "0.4.1-pre.0", + "@edfi/meadowlark-utilities": "0.4.1-pre.1", "@isaacs/ttlcache": "^1.4.1", "ajv": "^8.12.0", "ajv-formats": "^2.1.1", @@ -22743,7 +22743,7 @@ }, "packages/meadowlark-utilities": { "name": "@edfi/meadowlark-utilities", - "version": "0.4.1-pre.0", + "version": "0.4.1-pre.1", "license": "Apache-2.0", "dependencies": { "pino": "^8.15.7", @@ -22790,12 +22790,12 @@ }, "services/meadowlark-fastify": { "name": "@edfi/meadowlark-fastify", - "version": "0.4.1-pre.0", + "version": "0.4.1-pre.1", "license": "Apache-2.0", "dependencies": { - "@edfi/meadowlark-authz-server": "0.4.1-pre.0", - "@edfi/meadowlark-core": "0.4.1-pre.0", - "@edfi/meadowlark-utilities": "0.4.1-pre.0", + "@edfi/meadowlark-authz-server": "0.4.1-pre.1", + "@edfi/meadowlark-core": "0.4.1-pre.1", + "@edfi/meadowlark-utilities": "0.4.1-pre.1", "@fastify/rate-limit": "^6.0.1", "dotenv": "^16.3.1", "fastify": "^3.29.5" @@ -22808,10 +22808,10 @@ }, "tests/e2e": { "name": "@edfi/meadowlark-e2e-tests", - "version": "0.4.1-pre.0", + "version": "0.4.1-pre.1", "license": "Apache-2.0", "devDependencies": { - "@edfi/meadowlark-utilities": "0.4.1-pre.0", + "@edfi/meadowlark-utilities": "0.4.1-pre.1", "@testcontainers/mongodb": "^10.3.1", "@testcontainers/postgresql": "^10.3.1", "@types/chance": "^1.1.6", diff --git a/Meadowlark-js/packages/meadowlark-authz-server/package.json b/Meadowlark-js/packages/meadowlark-authz-server/package.json index dce307f1..840b0fad 100644 --- a/Meadowlark-js/packages/meadowlark-authz-server/package.json +++ b/Meadowlark-js/packages/meadowlark-authz-server/package.json @@ -1,7 +1,7 @@ { "name": "@edfi/meadowlark-authz-server", "main": "dist/index.js", - "version": "0.4.1-pre.0", + "version": "0.4.1-pre.1", "description": "Meadowlark authorization server", "license": "Apache-2.0", "publishConfig": { @@ -14,7 +14,7 @@ ], "dependencies": { "@apideck/better-ajv-errors": "^0.3.6", - "@edfi/meadowlark-utilities": "0.4.1-pre.0", + "@edfi/meadowlark-utilities": "0.4.1-pre.1", "ajv": "^8.12.0", "didyoumean2": "^6.0.1", "dotenv": "^16.3.1", diff --git a/Meadowlark-js/packages/meadowlark-core/package.json b/Meadowlark-js/packages/meadowlark-core/package.json index f08e6f4e..03685c22 100644 --- a/Meadowlark-js/packages/meadowlark-core/package.json +++ b/Meadowlark-js/packages/meadowlark-core/package.json @@ -1,7 +1,7 @@ { "name": "@edfi/meadowlark-core", "main": "dist/index.js", - "version": "0.4.1-pre.0", + "version": "0.4.1-pre.1", "description": "Meadowlark core functionality", "license": "Apache-2.0", "publishConfig": { @@ -14,7 +14,7 @@ ], "dependencies": { "@apideck/better-ajv-errors": "^0.3.6", - "@edfi/meadowlark-utilities": "0.4.1-pre.0", + "@edfi/meadowlark-utilities": "0.4.1-pre.1", "@isaacs/ttlcache": "^1.4.1", "ajv": "^8.12.0", "ajv-formats": "^2.1.1", diff --git a/Meadowlark-js/packages/meadowlark-utilities/package.json b/Meadowlark-js/packages/meadowlark-utilities/package.json index 1195fe3f..3b412a4f 100644 --- a/Meadowlark-js/packages/meadowlark-utilities/package.json +++ b/Meadowlark-js/packages/meadowlark-utilities/package.json @@ -1,7 +1,7 @@ { "name": "@edfi/meadowlark-utilities", "main": "dist/index.js", - "version": "0.4.1-pre.0", + "version": "0.4.1-pre.1", "description": "Meadowlark shared utilities", "license": "Apache-2.0", "publishConfig": { diff --git a/Meadowlark-js/services/meadowlark-fastify/package.json b/Meadowlark-js/services/meadowlark-fastify/package.json index 8e412430..f5b28edb 100644 --- a/Meadowlark-js/services/meadowlark-fastify/package.json +++ b/Meadowlark-js/services/meadowlark-fastify/package.json @@ -1,6 +1,6 @@ { "name": "@edfi/meadowlark-fastify", - "version": "0.4.1-pre.0", + "version": "0.4.1-pre.1", "description": "Meadowlark service using Fastify", "license": "Apache-2.0", "publishConfig": { @@ -12,9 +12,9 @@ "/package.json" ], "dependencies": { - "@edfi/meadowlark-authz-server": "0.4.1-pre.0", - "@edfi/meadowlark-core": "0.4.1-pre.0", - "@edfi/meadowlark-utilities": "0.4.1-pre.0", + "@edfi/meadowlark-authz-server": "0.4.1-pre.1", + "@edfi/meadowlark-core": "0.4.1-pre.1", + "@edfi/meadowlark-utilities": "0.4.1-pre.1", "@fastify/rate-limit": "^6.0.1", "dotenv": "^16.3.1", "fastify": "^3.29.5" diff --git a/Meadowlark-js/tests/e2e/helpers/Resources.ts b/Meadowlark-js/tests/e2e/helpers/Resources.ts index 6f052f64..918674f1 100644 --- a/Meadowlark-js/tests/e2e/helpers/Resources.ts +++ b/Meadowlark-js/tests/e2e/helpers/Resources.ts @@ -3,6 +3,7 @@ // The Ed-Fi Alliance licenses this file to you under the Apache License, Version 2.0. // See the LICENSE and NOTICES files in the project root for more information. +import request from 'supertest'; import { Role, getAccessToken } from './Credentials'; import { baseURLRequest, rootURLRequest } from './Shared'; @@ -54,3 +55,9 @@ export async function deleteResourceByLocation(location: string, resourceName = console.warn(`⚠️ Unable to delete ${resourceName}. Location not found. Verify that resource was created correctly ⚠️`); } } + +export async function getResourceByLocation(location: string): Promise { + return rootURLRequest() + .get(location) + .auth(await getAccessToken('host'), { type: 'bearer' }); +} diff --git a/Meadowlark-js/tests/e2e/package.json b/Meadowlark-js/tests/e2e/package.json index ee0d2ab7..4a8d298e 100644 --- a/Meadowlark-js/tests/e2e/package.json +++ b/Meadowlark-js/tests/e2e/package.json @@ -1,13 +1,13 @@ { "name": "@edfi/meadowlark-e2e-tests", "main": "dist/index.js", - "version": "0.4.1-pre.0", + "version": "0.4.1-pre.1", "description": "Meadowlark Ed-Fi API end to end tests", "license": "Apache-2.0", "private": true, "files": [], "devDependencies": { - "@edfi/meadowlark-utilities": "0.4.1-pre.0", + "@edfi/meadowlark-utilities": "0.4.1-pre.1", "@testcontainers/mongodb": "^10.3.1", "@testcontainers/postgresql": "^10.3.1", "@types/chance": "^1.1.6", diff --git a/Meadowlark-js/tests/e2e/scenarios/ResourcesCRUDValidation.test.ts b/Meadowlark-js/tests/e2e/scenarios/ResourcesCRUDValidation.test.ts index af5971da..5665748b 100644 --- a/Meadowlark-js/tests/e2e/scenarios/ResourcesCRUDValidation.test.ts +++ b/Meadowlark-js/tests/e2e/scenarios/ResourcesCRUDValidation.test.ts @@ -1,8 +1,10 @@ +import { Response } from 'supertest'; import { getAccessToken } from '../helpers/Credentials'; import { baseURLRequest, rootURLRequest } from '../helpers/Shared'; +import { createContentClassDescriptor } from '../helpers/DataCreation'; +import { deleteResourceByLocation, getResourceByLocation } from '../helpers/Resources'; describe('when performing crud operations', () => { - let resourceResponse; const resource = 'contentClassDescriptors'; const resourceEndpoint = `/v3.3b/ed-fi/${resource}`; const resourceBody = { @@ -29,73 +31,79 @@ describe('when performing crud operations', () => { }); describe('when creating a new resource', () => { + let createdResourceLocation: string; beforeAll(async () => { - await baseURLRequest() - .post(resourceEndpoint) - .auth(await getAccessToken('host'), { type: 'bearer' }) - .send(resourceBody) - .then((response) => { - resourceResponse = response; - }); + createdResourceLocation = await createContentClassDescriptor(); }); - it('returns 201', () => { - expect(resourceResponse.statusCode).toBe(201); + afterAll(async () => { + await deleteResourceByLocation(createdResourceLocation); + }); + + it('is created', () => { + expect(createdResourceLocation).toBeTruthy(); }); }); describe('when getting a resource by ID', () => { describe('given the resource exists', () => { - let getResponse; - it('returns 200', async () => { - await rootURLRequest() - .get(resourceResponse.headers.location) - .auth(await getAccessToken('host'), { type: 'bearer' }) - .expect(200) - .then((response) => { - getResponse = response; - }); + let createdResourceLocation: string; + let getResponse: Response; + + beforeAll(async () => { + createdResourceLocation = await createContentClassDescriptor(); + + getResponse = await getResourceByLocation(createdResourceLocation); + }); + + afterAll(async () => { + await deleteResourceByLocation(createdResourceLocation); + }); + + it('returns 200', () => { + expect(getResponse.statusCode).toEqual(200); }); it('returns its body successfully.', () => { expect(getResponse.body).toEqual(expect.objectContaining(resourceBody)); }); - }); - describe('given the resource does not exist', () => { - it('returns 404', async () => { - await rootURLRequest() - .get(`${resourceResponse.headers.location.slice(0, -1)}F`) - .auth(await getAccessToken('host'), { type: 'bearer' }) - .expect(404); + it('returns 404 when the resource does not exist', async () => { + const response = await getResourceByLocation(`${createdResourceLocation.slice(0, -1)}F`); + expect(response.statusCode).toEqual(404); }); - }); - it('should match the location', async () => { - const id = await rootURLRequest() - .get(resourceResponse.headers.location) - .auth(await getAccessToken('vendor'), { type: 'bearer' }) - .then((response) => response.body.id); + it('should match the location', async () => { + const id = await getResourceByLocation(createdResourceLocation).then((response) => response.body.id); - await baseURLRequest() - .get(`${resourceEndpoint}/${id}`) - .auth(await getAccessToken('vendor'), { type: 'bearer' }) - .expect(200); + const response = await baseURLRequest() + .get(`${resourceEndpoint}/${id}`) + .auth(await getAccessToken('host'), { type: 'bearer' }); + expect(response.statusCode).toEqual(200); - expect(resourceResponse.headers.location).toContain(`${resourceEndpoint}/${id}`); + expect(createdResourceLocation).toContain(`${resourceEndpoint}/${id}`); + }); }); }); describe('when getting all resources', () => { - let getAllResponse; - it('returns 200', async () => { - await baseURLRequest() + let createdResourceLocation: string; + let getAllResponse: Response; + + beforeAll(async () => { + createdResourceLocation = await createContentClassDescriptor(); + + getAllResponse = await baseURLRequest() .get(resourceEndpoint) - .auth(await getAccessToken('host'), { type: 'bearer' }) - .expect(200) - .then((response) => { - getAllResponse = response; - }); + .auth(await getAccessToken('host'), { type: 'bearer' }); + }); + + afterAll(async () => { + await deleteResourceByLocation(createdResourceLocation); + }); + + it('returns 200', () => { + expect(getAllResponse.statusCode).toEqual(200); }); it('returns one resource', async () => { @@ -104,43 +112,64 @@ describe('when performing crud operations', () => { }); describe('when upserting a resource', () => { - it('returns 200', async () => { - await baseURLRequest() + let createdResourceLocation: string; + let upsertResponse: Response; + + beforeAll(async () => { + createdResourceLocation = await createContentClassDescriptor(); + + upsertResponse = await baseURLRequest() .post(resourceEndpoint) .auth(await getAccessToken('host'), { type: 'bearer' }) - .send(resourceBodyUpdated) - .expect(200); + .send(resourceBodyUpdated); + }); + + afterAll(async () => { + await deleteResourceByLocation(createdResourceLocation); + }); + + it('returns 200', () => { + expect(upsertResponse.statusCode).toEqual(200); }); it('returns updated resource on get', async () => { - await rootURLRequest() - .get(resourceResponse.headers.location) - .auth(await getAccessToken('host'), { type: 'bearer' }) - .then((response) => { - expect(response.body).toEqual(expect.objectContaining(resourceBodyUpdated)); - }); + await getResourceByLocation(upsertResponse.headers.location).then((updatedResponse) => { + expect(updatedResponse.body).toEqual(expect.objectContaining(resourceBodyUpdated)); + }); }); }); - describe('when updating a resource with empty body', () => { - it('returns 400', async () => { - await rootURLRequest() - .put(resourceResponse.headers.location) + describe('when updating a resource', () => { + let createdResourceLocation: string; + + beforeAll(async () => { + createdResourceLocation = await createContentClassDescriptor(); + + await baseURLRequest() + .post(resourceEndpoint) .auth(await getAccessToken('host'), { type: 'bearer' }) - .send({}) - .expect(400); + .send(resourceBodyUpdated); + }); + + afterAll(async () => { + await deleteResourceByLocation(createdResourceLocation); + }); + + describe('when updating a resource with empty body', () => { + it('returns 400', async () => { + await rootURLRequest() + .put(createdResourceLocation) + .auth(await getAccessToken('host'), { type: 'bearer' }) + .send({}) + .expect(400); + }); }); - }); - describe('when updating a resource', () => { it('returns 204', async () => { - const id = await rootURLRequest() - .get(resourceResponse.headers.location) - .auth(await getAccessToken('vendor'), { type: 'bearer' }) - .then((response) => response.body.id); + const id = await getResourceByLocation(createdResourceLocation).then((response) => response.body.id); await rootURLRequest() - .put(resourceResponse.headers.location) + .put(createdResourceLocation) .auth(await getAccessToken('host'), { type: 'bearer' }) .send({ id, @@ -152,7 +181,7 @@ describe('when performing crud operations', () => { it('should fail when resource ID is different in body on put', async () => { const id = 'differentId'; await rootURLRequest() - .put(resourceResponse.headers.location) + .put(createdResourceLocation) .auth(await getAccessToken('host'), { type: 'bearer' }) .send({ id, @@ -170,7 +199,7 @@ describe('when performing crud operations', () => { it('should fail when resource ID is not included in body on put', async () => { await rootURLRequest() - .put(resourceResponse.headers.location) + .put(createdResourceLocation) .auth(await getAccessToken('host'), { type: 'bearer' }) .send(resourceBody) .expect(400) @@ -190,19 +219,14 @@ describe('when performing crud operations', () => { }); it('returns updated resource on get', async () => { - await rootURLRequest() - .get(resourceResponse.headers.location) - .auth(await getAccessToken('host'), { type: 'bearer' }) - .then((response) => { - expect(response.body).toEqual(expect.objectContaining(resourceBody)); - }); + await getResourceByLocation(createdResourceLocation).then((response) => { + expect(response.body).toEqual(expect.objectContaining(resourceBody)); + }); }); it('should fail when resource ID is included in body on post', async () => { - const id = await rootURLRequest() - .get(resourceResponse.headers.location) - .auth(await getAccessToken('host'), { type: 'bearer' }) - .then((response) => response.body.id); + const id = await getResourceByLocation(createdResourceLocation).then((response) => response.body.id); + await baseURLRequest() .post(`${resourceEndpoint}`) .auth(await getAccessToken('host'), { type: 'bearer' }) @@ -227,30 +251,31 @@ describe('when performing crud operations', () => { }); }); - describe('when deleting a resource that does not exist', () => { - it('returns 404', async () => { + describe('when deleting a resource', () => { + let createdResourceLocation: string; + let deleteResponse: Response; + beforeAll(async () => { + createdResourceLocation = await createContentClassDescriptor(); + + deleteResponse = await rootURLRequest() + .delete(createdResourceLocation) + .auth(await getAccessToken('host'), { type: 'bearer' }); + }); + + it('returns 404 when deleting a resource that does not exist', async () => { await rootURLRequest() - .delete(`${resourceResponse.headers.location.slice(0, -1)}F`) + .delete(`${createdResourceLocation.slice(0, -1)}F`) .auth(await getAccessToken('host'), { type: 'bearer' }) - .send(resourceBody) .expect(404); }); - }); - describe('when deleting a resource', () => { - it('returns 204', async () => { - await rootURLRequest() - .delete(resourceResponse.headers.location) - .auth(await getAccessToken('host'), { type: 'bearer' }) - .send(resourceBody) - .expect(204); + it('returns 204', () => { + expect(deleteResponse.statusCode).toEqual(204); }); it('returns 404 on get', async () => { - await rootURLRequest() - .get(resourceResponse.headers.location) - .auth(await getAccessToken('host'), { type: 'bearer' }) - .expect(404); + const response = await getResourceByLocation(createdResourceLocation); + expect(response.statusCode).toEqual(404); }); }); });