Skip to content

Commit

Permalink
feat(echo): sync version with package json (#5625)
Browse files Browse the repository at this point in the history
* feat(echo): sync version with package json

* refactor(package.json): update file paths in exports

* test(api): add echo health check e2e tests

* style: Fix extra space in test description

* test(content-templates): update assertion syntax

---------

Co-authored-by: Richard Fontein <32132657+rifont@users.noreply.github.com>
  • Loading branch information
2 people authored and SokratisVidros committed Jun 13, 2024
1 parent ec276f5 commit 4fffa6d
Show file tree
Hide file tree
Showing 7 changed files with 81 additions and 29 deletions.
2 changes: 1 addition & 1 deletion apps/api/e2e/echo.server.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as http from 'http';
import * as express from 'express';
// FIXME: subpath import not working with `workspace:` protocol. Currently we need to drill into the module instead of using the ES export.
import { serve } from '../../../packages/echo/dist/express';
import { serve } from '../../../packages/echo/dist/src/express';
import { Echo } from '@novu/echo';

class EchoServer {
Expand Down
4 changes: 2 additions & 2 deletions apps/api/src/app/content-templates/e2e/preview-email.e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ describe('Preview email - /v1/content-templates/preview/email (POST)', function
subject: 'test {{test}} test',
});

expect(html.includes('test test test')).true;
expect(subject.includes('test test test')).true;
expect(html).to.contain('test test test');
expect(subject).to.contain('test test test');
});
});
47 changes: 47 additions & 0 deletions apps/api/src/app/events/e2e/echo-health-check.e2e-ee.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import axios from 'axios';
import { expect } from 'chai';
import { UserSession, SubscribersService } from '@novu/testing';
import { SubscriberEntity } from '@novu/dal';
import { echoServer } from '../../../../e2e/echo.server';

describe('Echo Health Check', async () => {
let session: UserSession;
let subscriber: SubscriberEntity;
let subscriberService: SubscribersService;

before(async () => {
await echoServer.echo.workflow('health-check', async ({ step }) => {
await step.email('send-email', async (inputs) => {
return {
subject: 'This is an email subject',
body: 'Body result',
};
});
});
});

beforeEach(async () => {
session = new UserSession();
await session.initialize();
subscriberService = new SubscribersService(session.organization._id, session.environment._id);
subscriber = await subscriberService.createSubscriber();
});

it('should have a status', async () => {
const result = await axios.get(echoServer.serverPath + '/echo?action=health-check');

expect(result.data.status).to.equal('ok');
});

it('should have a version', async () => {
const result = await axios.get(echoServer.serverPath + '/echo?action=health-check');

expect(result.data.version).to.be.a('string');
});

it('should return the discovered resources', async () => {
const result = await axios.get(echoServer.serverPath + '/echo?action=health-check');

expect(result.data.discovered).to.deep.equal({ workflows: 1, steps: 1 });
});
});
35 changes: 18 additions & 17 deletions packages/echo/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
"name": "@novu/echo",
"version": "0.24.3-alpha.0",
"description": "The Code-First Notifications Workflow SDK.",
"main": "./dist/index.js",
"types": "./dist/index.d.ts",
"main": "./dist/src/index.js",
"types": "./dist/src/index.d.ts",
"publishConfig": {
"registry": "https://registry.npmjs.org",
"access": "public"
Expand All @@ -18,6 +18,7 @@
"format": "prettier --check --ignore-path .gitignore .",
"format:fix": "prettier --write --ignore-path .gitignore .",
"clean": "rm -rf ./dist",
"prebuild": "rimraf dist",
"build": "pnpm run clean && tsc --build",
"build:watch": "tsc --build --watch",
"$comment:bump:prerelease": "This is a workaround to support `npm version prerelease` with lerna",
Expand All @@ -44,29 +45,29 @@
"license": "MIT",
"exports": {
".": {
"require": "./dist/index.js",
"import": "./dist/index.js",
"types": "./dist/index.d.ts"
"require": "./dist/src/index.js",
"import": "./dist/src/index.js",
"types": "./dist/src/index.d.ts"
},
"./express": {
"require": "./dist/express.js",
"import": "./dist/express.js",
"types": "./dist/express.d.ts"
"require": "./dist/src/express.js",
"import": "./dist/src/express.js",
"types": "./dist/src/express.d.ts"
},
"./next": {
"require": "./dist/next.js",
"import": "./dist/next.js",
"types": "./dist/next.d.ts"
"require": "./dist/src/next.js",
"import": "./dist/src/next.js",
"types": "./dist/src/next.d.ts"
},
"./nuxt": {
"require": "./dist/nuxt.js",
"import": "./dist/nuxt.js",
"types": "./dist/nuxt.d.ts"
"require": "./dist/src/nuxt.js",
"import": "./dist/src/nuxt.js",
"types": "./dist/src/nuxt.d.ts"
},
"./h3": {
"require": "./dist/h3.js",
"import": "./dist/h3.js",
"types": "./dist/h3.d.ts"
"require": "./dist/src/h3.js",
"import": "./dist/src/h3.js",
"types": "./dist/src/h3.d.ts"
}
},
"devDependencies": {
Expand Down
9 changes: 9 additions & 0 deletions packages/echo/src/version.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { VERSION } from './version';

describe('version', () => {
test('should export the current version', () => {
const importVersion = VERSION;
const packageJsonVersion = require('../package.json').version;
expect(importVersion).toEqual(packageJsonVersion);
});
});
9 changes: 2 additions & 7 deletions packages/echo/src/version.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
// import packageJson from '../package.json'
import packageJson from '../package.json';

/**
* @TODO: Replace with the package version
* Need to figure out how to get the package version in the SDK
* export const VERSION = packageJson.version
*/
export const VERSION = '0.0.1';
export const VERSION = packageJson.version;
4 changes: 2 additions & 2 deletions packages/echo/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@
"declaration": true,
"declarationMap": true,
"sourceMap": true,
"rootDir": "./src",
"rootDir": ".",
"outDir": "./dist",
"strictNullChecks": true
},
"include": ["./src/**/*"],
"include": ["./src/**/*", "./package.json"],
"exclude": ["node_modules", "**/*.spec.ts"]
}

0 comments on commit 4fffa6d

Please sign in to comment.