Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,12 @@
},
"devDependencies": {
"@nx/js": "22.5.3",
"@vitest/coverage-v8": "3.1.1",
"eslint": "8.57.1",
"eslint-plugin-ghost": "3.4.4",
"mocha": "11.7.5",
"nx": "22.5.3",
"sinon": "21.0.1",
"ts-node": "10.9.2"
"ts-node": "10.9.2",
"vitest": "3.1.1"
}
}
3 changes: 1 addition & 2 deletions packages/api-framework/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"main": "index.js",
"scripts": {
"dev": "echo \"Implement me!\"",
"test:unit": "NODE_ENV=testing c8 --all --reporter text --reporter cobertura --check-coverage --100 -- mocha --reporter dot './test/**/*.test.js'",
"test:unit": "NODE_ENV=testing vitest run --coverage --config ../../vitest.config.ts",
"test": "yarn test:unit",
"lint:code": "eslint *.js lib/ --ext .js --cache",
"lint": "yarn lint:code && yarn lint:test",
Expand All @@ -24,7 +24,6 @@
"lib"
],
"devDependencies": {
"c8": "11.0.0",
"mocha": "11.7.5",
"sinon": "21.0.1"
},
Expand Down
210 changes: 112 additions & 98 deletions packages/api-framework/test/http.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,129 +65,143 @@ describe('HTTP', function () {
});
});

it('api response is fn', function (done) {
const response = sinon.stub().callsFake(function (_req, _res, _next) {
assert.ok(_req);
assert.ok(_res);
assert.ok(_next);
assert.equal(apiImpl.calledOnce, true);
assert.equal(_res.json.called, false);
done();
});
it('api response is fn', async function () {
await new Promise((resolve) => {
const response = sinon.stub().callsFake(function (_req, _res, _next) {
assert.ok(_req);
assert.ok(_res);
assert.ok(_next);
assert.equal(apiImpl.calledOnce, true);
assert.equal(_res.json.called, false);
resolve();
});

const apiImpl = sinon.stub().resolves(response);
shared.http(apiImpl)(req, res, next);
const apiImpl = sinon.stub().resolves(response);
shared.http(apiImpl)(req, res, next);
});
});

it('api response is fn (data)', function (done) {
const apiImpl = sinon.stub().resolves('data');
it('api response is fn (data)', async function () {
await new Promise((resolve) => {
const apiImpl = sinon.stub().resolves('data');

next.callsFake(done);
next.callsFake(resolve);

res.json.callsFake(function () {
assert.equal(shared.headers.get.calledOnce, true);
assert.equal(res.status.calledOnce, true);
assert.equal(res.send.called, false);
done();
});
res.json.callsFake(function () {
assert.equal(shared.headers.get.calledOnce, true);
assert.equal(res.status.calledOnce, true);
assert.equal(res.send.called, false);
resolve();
});

shared.http(apiImpl)(req, res, next);
shared.http(apiImpl)(req, res, next);
});
});

it('handles api key, user and plain text response', function (done) {
req.vhost = null;
req.user = {id: 'user-id'};
req.api_key = {
get(key) {
return {
id: 'api-key-id',
type: 'admin',
integration_id: 'integration-id'
}[key];
}
};

const apiImpl = sinon.stub().resolves('plain body');
apiImpl.response = {format: 'plain'};
apiImpl.statusCode = 201;

res.send.callsFake(() => {
assert.equal(res.status.calledOnceWithExactly(201), true);
assert.equal(res.headers.constructor, Object);
assert.equal(res.json.called, false);
it('handles api key, user and plain text response', async function () {
await new Promise((resolve) => {
req.vhost = null;
req.user = {id: 'user-id'};
req.api_key = {
get(key) {
return {
id: 'api-key-id',
type: 'admin',
integration_id: 'integration-id'
}[key];
}
};

const apiImpl = sinon.stub().resolves('plain body');
apiImpl.response = {format: 'plain'};
apiImpl.statusCode = 201;

res.send.callsFake(() => {
assert.equal(res.status.calledOnceWithExactly(201), true);
assert.equal(res.headers.constructor, Object);
assert.equal(res.json.called, false);

const frame = apiImpl.args[0][0];
assert.equal(frame.options.context.api_key.id, 'api-key-id');
assert.equal(frame.options.context.integration.id, 'integration-id');
assert.equal(frame.options.context.user, 'user-id');
resolve();
});

const frame = apiImpl.args[0][0];
assert.equal(frame.options.context.api_key.id, 'api-key-id');
assert.equal(frame.options.context.integration.id, 'integration-id');
assert.equal(frame.options.context.user, 'user-id');
done();
shared.http(apiImpl)(req, res, next);
});

shared.http(apiImpl)(req, res, next);
});

it('supports async response format and statusCode function', function (done) {
const apiImpl = sinon.stub().resolves({ok: true});
apiImpl.statusCode = sinon.stub().returns(204);
apiImpl.response = {
format() {
return Promise.resolve('plain');
}
};
it('supports async response format and statusCode function', async function () {
await new Promise((resolve) => {
const apiImpl = sinon.stub().resolves({ok: true});
apiImpl.statusCode = sinon.stub().returns(204);
apiImpl.response = {
format() {
return Promise.resolve('plain');
}
};

res.send.callsFake(() => {
assert.equal(apiImpl.statusCode.calledOnce, true);
assert.equal(res.status.calledOnceWithExactly(204), true);
resolve();
});

res.send.callsFake(() => {
assert.equal(apiImpl.statusCode.calledOnce, true);
assert.equal(res.status.calledOnceWithExactly(204), true);
done();
shared.http(apiImpl)(req, res, next);
});

shared.http(apiImpl)(req, res, next);
});

it('supports sync response format function', function (done) {
const apiImpl = sinon.stub().resolves('plain body');
apiImpl.response = {
format() {
return 'plain';
}
};
it('supports sync response format function', async function () {
await new Promise((resolve) => {
const apiImpl = sinon.stub().resolves('plain body');
apiImpl.response = {
format() {
return 'plain';
}
};

res.send.callsFake(() => {
assert.equal(res.send.calledOnce, true);
assert.equal(res.json.called, false);
resolve();
});

res.send.callsFake(() => {
assert.equal(res.send.calledOnce, true);
assert.equal(res.json.called, false);
done();
shared.http(apiImpl)(req, res, next);
});

shared.http(apiImpl)(req, res, next);
});

it('passes errors to next with frame options', function (done) {
const error = new Error('failure');
const apiImpl = sinon.stub().rejects(error);

next.callsFake((err) => {
assert.equal(err, error);
assert.deepEqual(req.frameOptions, {
docName: null,
method: null
it('passes errors to next with frame options', async function () {
await new Promise((resolve) => {
const error = new Error('failure');
const apiImpl = sinon.stub().rejects(error);

next.callsFake((err) => {
assert.equal(err, error);
assert.deepEqual(req.frameOptions, {
docName: null,
method: null
});
resolve();
});
done();
});

shared.http(apiImpl)(req, res, next);
shared.http(apiImpl)(req, res, next);
});
});

it('uses req.url pathname when originalUrl is missing', function (done) {
req.originalUrl = undefined;
req.url = '/ghost/api/content/posts/?include=authors';
it('uses req.url pathname when originalUrl is missing', async function () {
await new Promise((resolve) => {
req.originalUrl = undefined;
req.url = '/ghost/api/content/posts/?include=authors';

const apiImpl = sinon.stub().resolves({});
res.json.callsFake(() => {
const frame = apiImpl.args[0][0];
assert.equal(frame.original.url.pathname, '/ghost/api/content/posts/');
done();
});
const apiImpl = sinon.stub().resolves({});
res.json.callsFake(() => {
const frame = apiImpl.args[0][0];
assert.equal(frame.original.url.pathname, '/ghost/api/content/posts/');
resolve();
});

shared.http(apiImpl)(req, res, next);
shared.http(apiImpl)(req, res, next);
});
});
});
3 changes: 1 addition & 2 deletions packages/bookshelf-collision/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"main": "index.js",
"scripts": {
"dev": "echo \"Implement me!\"",
"test": "NODE_ENV=testing c8 --all --reporter text --reporter cobertura --check-coverage --100 -- mocha './test/**/*.test.js'",
"test": "NODE_ENV=testing vitest run --coverage --config ../../vitest.config.ts",
"lint": "eslint . --ext .js --cache",
"posttest": "yarn lint"
},
Expand All @@ -23,7 +23,6 @@
"access": "public"
},
"devDependencies": {
"c8": "11.0.0",
"mocha": "11.7.5",
"sinon": "21.0.1"
},
Expand Down
3 changes: 1 addition & 2 deletions packages/bookshelf-custom-query/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"main": "index.js",
"scripts": {
"dev": "echo \"Implement me!\"",
"test": "NODE_ENV=testing c8 --all --reporter text --reporter cobertura --check-coverage --100 -- mocha './test/**/*.test.js'",
"test": "NODE_ENV=testing vitest run --coverage --config ../../vitest.config.ts",
"lint": "eslint . --ext .js --cache",
"posttest": "yarn lint"
},
Expand All @@ -23,7 +23,6 @@
"access": "public"
},
"devDependencies": {
"c8": "11.0.0",
"mocha": "11.7.5",
"sinon": "21.0.1"
}
Expand Down
3 changes: 1 addition & 2 deletions packages/bookshelf-eager-load/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"main": "index.js",
"scripts": {
"dev": "echo \"Implement me!\"",
"test": "NODE_ENV=testing c8 --all --reporter text --reporter cobertura --check-coverage --100 -- mocha './test/**/*.test.js'",
"test": "NODE_ENV=testing vitest run --coverage --config ../../vitest.config.ts",
"lint": "eslint . --ext .js --cache",
"posttest": "yarn lint"
},
Expand All @@ -23,7 +23,6 @@
"access": "public"
},
"devDependencies": {
"c8": "11.0.0",
"mocha": "11.7.5",
"sinon": "21.0.1"
},
Expand Down
3 changes: 1 addition & 2 deletions packages/bookshelf-filter/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"main": "index.js",
"scripts": {
"dev": "echo \"Implement me!\"",
"test": "NODE_ENV=testing c8 --all --reporter text --reporter cobertura --check-coverage --100 -- mocha './test/**/*.test.js'",
"test": "NODE_ENV=testing vitest run --coverage --config ../../vitest.config.ts",
"lint": "eslint . --ext .js --cache",
"posttest": "yarn lint"
},
Expand All @@ -23,7 +23,6 @@
"access": "public"
},
"devDependencies": {
"c8": "11.0.0",
"mocha": "11.7.5",
"sinon": "21.0.1"
},
Expand Down
3 changes: 1 addition & 2 deletions packages/bookshelf-has-posts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"main": "index.js",
"scripts": {
"dev": "echo \"Implement me!\"",
"test": "NODE_ENV=testing c8 --all --reporter text --reporter cobertura --check-coverage --100 -- mocha './test/**/*.test.js'",
"test": "NODE_ENV=testing vitest run --coverage --config ../../vitest.config.ts",
"lint": "eslint . --ext .js --cache",
"posttest": "yarn lint"
},
Expand All @@ -23,7 +23,6 @@
"access": "public"
},
"devDependencies": {
"c8": "11.0.0",
"mocha": "11.7.5",
"sinon": "21.0.1"
},
Expand Down
3 changes: 1 addition & 2 deletions packages/bookshelf-include-count/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"main": "index.js",
"scripts": {
"dev": "echo \"Implement me!\"",
"test": "NODE_ENV=testing c8 --all --reporter text --reporter cobertura --check-coverage --100 -- mocha './test/**/*.test.js'",
"test": "NODE_ENV=testing vitest run --coverage --config ../../vitest.config.ts",
"lint": "eslint . --ext .js --cache",
"posttest": "yarn lint"
},
Expand All @@ -23,7 +23,6 @@
"access": "public"
},
"devDependencies": {
"c8": "11.0.0",
"mocha": "11.7.5",
"sinon": "21.0.1"
},
Expand Down
3 changes: 1 addition & 2 deletions packages/bookshelf-order/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"main": "index.js",
"scripts": {
"dev": "echo \"Implement me!\"",
"test": "NODE_ENV=testing c8 --all --reporter text --reporter cobertura --check-coverage --100 -- mocha './test/**/*.test.js'",
"test": "NODE_ENV=testing vitest run --coverage --config ../../vitest.config.ts",
"lint": "eslint . --ext .js --cache",
"posttest": "yarn lint"
},
Expand All @@ -23,7 +23,6 @@
"access": "public"
},
"devDependencies": {
"c8": "11.0.0",
"mocha": "11.7.5",
"sinon": "21.0.1"
},
Expand Down
Loading
Loading