Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(tests): noteList.test #95

Closed
wants to merge 48 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
ec9e79c
feat: add default tool to user editor tools
GeekaN2 Oct 22, 2023
2746ae9
refactoring: get rid of underscore from code
neSpecc Oct 22, 2023
bd21b03
fix: migrations
neSpecc Oct 22, 2023
648fee1
rm unused option
neSpecc Oct 22, 2023
ef2e923
feat(noteList.test)
e11sy Oct 22, 2023
7c3d212
chore: move bis-logic from ui do domain, decouple domains
neSpecc Oct 22, 2023
4e71ad0
comment fixes
e11sy Oct 22, 2023
239ec7c
Update README.md
neSpecc Oct 22, 2023
55cba15
Merge pull request #96 from codex-team/feat/shared-domains
neSpecc Oct 22, 2023
a4d6340
chore: fix alias tests
GeekaN2 Oct 23, 2023
3e7fc8f
fixed sql syntax
e11sy Oct 23, 2023
c85ca2f
fixed sql syntax
e11sy Oct 23, 2023
ce0099e
changed variable name
e11sy Oct 23, 2023
fa36e2e
fix readme
neSpecc Oct 23, 2023
458bfbc
Merge pull request #94 from codex-team/feat/default-tools
neSpecc Oct 23, 2023
63925ee
Divided enlist and build-push action to 2 separated actions
GoldenJaden Oct 23, 2023
dfd1eae
Added build check workflow
GoldenJaden Oct 24, 2023
b7e9358
Workflows for API
GoldenJaden Oct 24, 2023
00acf42
fix
GoldenJaden Oct 24, 2023
aa12af4
access_token is undefined
e11sy Oct 26, 2023
b4704d8
deleted unwanted changes
e11sy Oct 26, 2023
1da02f9
Merge pull request #98 from GoldenJaden/separate-enlist-build-action
GoldenJaden Oct 26, 2023
3c3e39a
Testcases were written for the get note by id method
elizachi Oct 27, 2023
29c81a5
fix: test auth
neSpecc Oct 27, 2023
6cda662
fix description and oublic id of the test cases
elizachi Oct 28, 2023
73c0904
added path to the tests folder for importing test data
elizachi Oct 30, 2023
c600498
removed undefined check
elizachi Oct 30, 2023
f8c340e
Quickfix: added synchronize trigger on PR to actions
GoldenJaden Oct 31, 2023
9b23f32
Merge pull request #101 from GoldenJaden/quickfix-PR-action
GoldenJaden Oct 31, 2023
ea09309
quickFix(tests): logic fixes
e11sy Oct 31, 2023
eef6a67
push trigger fix
kloV148 Nov 1, 2023
d30bde3
added reopened trigger
kloV148 Nov 1, 2023
d3fddaf
Merge pull request #102 from kloV148/gh-actions-fix
kloV148 Nov 1, 2023
d3e68a0
Added another test case, but it doesn't work yet.
elizachi Nov 1, 2023
bfc4515
Add TODO position from review
elizachi Nov 2, 2023
aca5ee8
Use response?.json() instead of manually parsing body
elizachi Nov 2, 2023
00bc8b1
Changed the description of the test cases, added @todo
elizachi Nov 2, 2023
55fc668
Added test case with id cintains incorrect characters
elizachi Nov 2, 2023
d249467
Fix test case and @todo description
elizachi Nov 2, 2023
e684572
Move all @todo to the end of test cases
elizachi Nov 2, 2023
f319bee
Added 3 test cases for status 400
elizachi Nov 2, 2023
563227e
Merge pull request #99 from codex-team/chore/get-note-by-id-tests
elizachi Nov 3, 2023
2f5ea30
feat(tests) : auth method added
e11sy Nov 5, 2023
0a998e8
chore(tests): readme info added
e11sy Nov 5, 2023
a149b00
chore(tests): rename variable
e11sy Nov 5, 2023
01cb4c9
Merge pull request #104 from codex-team/auth-method-tests
e11sy Nov 6, 2023
1866054
Merge branch 'noteList.test'
e11sy Nov 6, 2023
3df5b25
chore(tests): auth method changed
e11sy Nov 7, 2023
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
Original file line number Diff line number Diff line change
@@ -1,35 +1,21 @@
name: Build and push docker image
name: Deploy API

on:
push:
branches:
- '*'
- 'main'
tags:
- 'v*'

env:
REGISTRY: ghcr.io

jobs:
eslint:
name: Run eslint check
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Install dependencies
run: |
yarn install

- name: Run ESLint
run: yarn lint

build:
runs-on: ubuntu-22.04

steps:
- name: Checkout repository
- name: Checkout Repository
uses: actions/checkout@v3

- name: Get full image name
Expand Down
33 changes: 33 additions & 0 deletions .github/workflows/run-build-check.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: Run build check

on:
push:
branches:
- 'main'
tags:
- 'v*'

pull_request:
types: [opened, synchronize, reopened]

jobs:
build:
name: Run yarn build
runs-on: ubuntu-22.04

steps:
- name: Checkout Repository
uses: actions/checkout@v3

- name: Setup node
uses: actions/setup-node@v3
with:
node-version: 20

- name: Install dependencies
run: yarn install

- name: Build
run: yarn build


26 changes: 26 additions & 0 deletions .github/workflows/run-eslint-check.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: Run ESlint check

on:
push:
branches:
- 'main'
tags:
- 'v*'

pull_request:
types: [opened, synchronize, reopened]

jobs:
eslint:
name: Run eslint check
runs-on: ubuntu-22.04
steps:
- name: Checkout Repository
uses: actions/checkout@v3

- name: Install dependencies
run: |
yarn install

- name: Run ESLint
run: yarn lint
9 changes: 7 additions & 2 deletions .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
name: Run tests

on:
pull_request:
push:
branches:
- '*'
- 'main'
tags:
- 'v*'

pull_request:
types: [opened, synchronize, reopened]

jobs:
tests:
Expand Down
22 changes: 22 additions & 0 deletions migrations/tenant/[email protected]
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@

-- Adds "editor_tools" column at "users" if not exists
DO $$
BEGIN
IF NOT EXISTS(SELECT *
FROM information_schema.columns
WHERE table_name='users' and column_name='editor_tools')
THEN
ALTER TABLE "public"."users" ADD COLUMN "editor_tools" jsonb;
END IF;
END $$;

-- Removes "extensions" column at "users" if exists
DO $$
BEGIN
IF EXISTS(SELECT *
FROM information_schema.columns
WHERE table_name='users' and column_name='extensions')
THEN
ALTER TABLE "public"."users" DROP COLUMN "extensions";
END IF;
END $$;
33 changes: 33 additions & 0 deletions migrations/tenant/[email protected]
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
-- "editor_tools" table:

-- Rename column "isDefault" to "is_default" if "isDefault" exists and "is_default" not exists
DO $$
BEGIN
IF EXISTS(SELECT *
FROM information_schema.columns
WHERE table_name='editor_tools' and column_name='isDefault')
THEN
IF NOT EXISTS(SELECT *
FROM information_schema.columns
WHERE table_name='editor_tools' and column_name='is_default')
THEN
ALTER TABLE "public"."editor_tools" RENAME COLUMN "isDefault" TO "is_default";
END IF;
END IF;
END $$;

-- Rename column "exportName" to "export_name" if "exportName" exists and "export_name" not exists
DO $$
BEGIN
IF EXISTS(SELECT *
FROM information_schema.columns
WHERE table_name='editor_tools' and column_name='exportName')
THEN
IF NOT EXISTS(SELECT *
FROM information_schema.columns
WHERE table_name='editor_tools' and column_name='export_name')
THEN
ALTER TABLE "public"."editor_tools" RENAME COLUMN "exportName" TO "export_name";
END IF;
END IF;
END $$;
7 changes: 3 additions & 4 deletions src/domain/entities/user.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type UserExtensions from '@domain/entities/userExtensions.js';
import type EditorTool from './editorTools';

/**
* User entity
Expand Down Expand Up @@ -30,8 +30,7 @@ export default interface User {
photo?: string;

/**
* Custom plugins from the marketplace that improve
* editor or notes environment
* Custom plugins ids from the marketplace that improve editor or notes environment
*/
extensions?: UserExtensions;
editorTools?: EditorTool['id'][];
}
19 changes: 0 additions & 19 deletions src/domain/entities/userExtensions.ts

This file was deleted.

10 changes: 7 additions & 3 deletions src/domain/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,14 @@ export function init(repositories: Repositories, appConfig: AppConfig): DomainSe
repositories.userSessionRepository
);

const userService = new UserService(repositories.userRepository);

const aiService = new AIService(repositories.aiRepository);
const editorToolsService = new EditorToolsService(repositories.editorToolsRepository);
const userService = new UserService(repositories.userRepository, {
editorTools: editorToolsService,
/**
* @todo find a way how to resolve circular dependency
*/
});
const aiService = new AIService(repositories.aiRepository);

return {
noteService,
Expand Down
12 changes: 10 additions & 2 deletions src/domain/service/editorTools.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import type EditorToolsRepository from '@repository/editorTools.repository.js';
import type EditorTool from '@domain/entities/editorTools.js';
import { createEditorToolId } from '@infrastructure/utils/id.js';
import type EditorToolsServiceSharedMethods from './shared/editorTools.js';

/**
* Editor tools service
*/
export default class EditorToolsService {
export default class EditorToolsService implements EditorToolsServiceSharedMethods {
/**
* User repository instance
*/
Expand All @@ -32,10 +33,17 @@ export default class EditorToolsService {
*
* @param editorToolIds - tool ids
*/
public async getToolsByIds(editorToolIds: EditorTool['id'][] ): Promise<EditorTool[] | null> {
public async getToolsByIds(editorToolIds: EditorTool['id'][]): Promise<EditorTool[]> {
return await this.repository.getToolsByIds(editorToolIds);
}

/**
* Return tools that are available at Editor by default
*/
public async getDefaultTools(): Promise<EditorTool[]> {
return await this.repository.getDefaultTools();
}

/**
* Adding custom editor tool
*
Expand Down
30 changes: 30 additions & 0 deletions src/domain/service/shared/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Shared Domain Services

Sometimes you may want to call some domain method from other domain. We can inject them in constructor, but it creates a direct dependency.

One way do decouple domains is to create a Shared Interfaces — domain will "expose" some public methods though it. You can call it "Contract".
So dependant domain will depend on it instead of direct dependency.


## Example

```ts
interface DomainASharedMethods {
someMethodA: () => void;
}

export type SharedDomainMethods = {
domainA: DomainASharedMethods;
};


class DomainA implements DomainASharedMethods {
public someMethodA (){}
}

class DomainB {
constructor(private readonly shared: SharedDomainMethods) {
this.shared.domainA.someMethodA(); // here we call method of Domain A, but without direct dependency
}
}
```
19 changes: 19 additions & 0 deletions src/domain/service/shared/editorTools.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import type EditorTool from '@domain/entities/editorTools';

/**
* Which methods of Domain can be used by other domains
* Uses to decouple domains from each other
*/
export default interface EditorToolsServiceSharedMethods {
/**
* Return tools that are available at Editor by default
*/
getDefaultTools(): Promise<EditorTool[]>;

/**
* Get bunch of editor tools by their ids
*
* @param ids - tool ids to resolve
*/
getToolsByIds(ids: EditorTool['id'][]): Promise<EditorTool[]>;
}
5 changes: 5 additions & 0 deletions src/domain/service/shared/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import type EditorToolsServiceSharedMethods from './editorTools';

export type SharedDomainMethods = {
editorTools: EditorToolsServiceSharedMethods;
};
33 changes: 23 additions & 10 deletions src/domain/service/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import type UserRepository from '@repository/user.repository.js';
import { Provider } from '@repository/user.repository.js';
import type User from '@domain/entities/user.js';
import type EditorTool from '@domain/entities/editorTools';
import type { SharedDomainMethods } from './shared/index.js';

export {
Provider
Expand All @@ -20,8 +21,9 @@ export default class UserService {
* User service constructor
*
* @param repository - user repository instance
* @param shared - shared domains
*/
constructor(repository: UserRepository) {
constructor(repository: UserRepository, private readonly shared: SharedDomainMethods) {
this.repository = repository;
}

Expand All @@ -47,15 +49,28 @@ export default class UserService {
}

/**
* Get user extensions that contains only editoTools for now
* TODO: Simplify extenisons
* Get user editor tools ids
*
* @param userId - user unique identifier
*/
public async getUserExtensions(userId: User['id']): Promise<User['extensions']> {
public async getUserEditorTools(userId: User['id']): Promise<EditorTool[]> {
const user = await this.getUserById(userId);

return user?.extensions ?? {};
if (user === null) {
throw new Error('User not found');
}

const userToolsIds = user.editorTools ?? [];
const defaultTools = await this.shared.editorTools.getDefaultTools();
const uniqueDefaultEditorTools = defaultTools.filter(({ id }) => !userToolsIds.includes(id));
const userTools = await this.shared.editorTools.getToolsByIds(userToolsIds) ?? [];

/**
* Combine user tools and default tools
*
* @todo load tools in notes service
*/
return [...userTools, ...uniqueDefaultEditorTools];
}

/**
Expand All @@ -65,16 +80,14 @@ export default class UserService {
*/
public async addUserEditorTool({
userId,
editorToolId,
toolId,
}: {
userId: User['id'],
editorToolId: EditorTool['id'],
toolId: EditorTool['id'],
}): Promise<void> {
return await this.repository.addUserEditorTool({
userId,
tool: {
id: editorToolId,
},
toolId,
});
}
}
Loading