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

Project rename #56

Merged
merged 20 commits into from
Nov 1, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
0f8357e
feat(snippet): create query to retrieve public snippets
tericcabrel Oct 23, 2022
a320850
feat(snippet): browse snippets
tericcabrel Oct 30, 2022
09c18ce
chore(snippet): create the column to save the highlighted snippet
tericcabrel Oct 30, 2022
fc0449f
enh(core): add content highlighted in the snippet schema
tericcabrel Oct 30, 2022
e310f48
feat(snippet): include the highlighted when creating a snippet
tericcabrel Oct 30, 2022
ceac0b3
feat(snippet): include the highlighted when updating a snippet
tericcabrel Oct 30, 2022
113d08a
test(snippet): write tests case for updating and deleting a snippet
tericcabrel Oct 30, 2022
e4ec3ef
test(domain): test the newsletter service
tericcabrel Oct 30, 2022
a347896
test(domain): test folders deletion
tericcabrel Oct 30, 2022
8b8d899
test(domain): test users service remaining cases
tericcabrel Oct 30, 2022
5d85638
feat(snippet): manually select the language of a code snippet
tericcabrel Nov 9, 2022
c905424
feat(snippet): set the current language as the default when editing
tericcabrel Nov 11, 2022
658c924
feat(snippet): update the resolver to retrieve snippet content
tericcabrel Nov 12, 2022
2529007
style(snippet): style the code preview on snippets list
tericcabrel Nov 14, 2022
c771084
style(snippet): complete the ui to browse public snippet
tericcabrel Nov 20, 2022
d76d74a
chore(web): replace default exports with named exports
tericcabrel Nov 20, 2022
89a3002
feat(snippet): write the client query to find public snippets
tericcabrel Nov 21, 2022
5df324d
feat(snippet): implement pagination navigation on client side - wip
tericcabrel Nov 22, 2022
0f8a8ff
feat(snippet): add more filter on public snippets query
tericcabrel Nov 24, 2022
7d0d781
chore: project rename
tericcabrel Nov 1, 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
Prev Previous commit
Next Next commit
chore(snippet): create the column to save the highlighted snippet
  • Loading branch information
tericcabrel committed Oct 30, 2022
commit 09c18ce7350b0193041721c5643635b4bdc6dae1
2 changes: 1 addition & 1 deletion packages/database/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"lint": "eslint src index.ts",
"test": "jest",
"db:dev": "pscale connect sharingan dev --port 3311",
"db:shadow": "docker run -d --rm -e MYSQL_ROOT_PASSWORD=secret -e MYSQL_DATABASE=sharingan --name sharingan-shadow-db -p 3312:3306 mysql:8.0",
"db:shadow": "docker run -d --rm -e MYSQL_ROOT_PASSWORD=secret -e MYSQL_DATABASE=sharingan --name sharingan-shadow-db -p 3312:3306 mysql:8.0.23",
"db:shadow:stop": "docker kill sharingan-shadow-db && docker container prune -f",
"db:deploy:create": "pscale deploy-request create sharingan dev",
"db:generate": "prisma generate --schema=./prisma/schema.prisma",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
-- AlterTable
ALTER TABLE `snippets` ADD COLUMN `content_html` TEXT NULL;
1 change: 1 addition & 0 deletions packages/database/prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ model Snippet {
folderId String @map("folder_id")
name String @db.VarChar(255)
content String @db.Text
contentHtml String? @db.Text @map("content_html")
language String @db.VarChar(20)
size Int @default(0) @db.Int
visibility SnippetVisibility @default(public)
Expand Down
1 change: 1 addition & 0 deletions packages/database/prisma/schema.test.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ model Snippet {
folderId String @map("folder_id")
name String @db.VarChar(255)
content String @db.Text
contentHtml String? @db.Text @map("content_html")
language String @db.VarChar(20)
size Int @default(0) @db.Int
visibility SnippetVisibility @default(public)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ describe('Test Create Snippet DTO', () => {
// GIVEN
const dto = new CreateSessionDto({
content: 'import React from "react";\n\nexport const App = () => {\n\n\treturn(\n\t\t<div>Hello</div>\n\t);\n};',
contentHighlighted:
'import React from "react";\n\nexport const App = () => {\n\n\treturn(\n\t\t<div>Hello</div>\n\t);\n}; highlighted',
description: 'Basic react component',
folderId,
language: 'tsx',
Expand All @@ -27,6 +29,8 @@ describe('Test Create Snippet DTO', () => {
// THEN
expect(folder).toMatchObject<Snippet>({
content: 'import React from "react";\n\nexport const App = () => {\n\n\treturn(\n\t\t<div>Hello</div>\n\t);\n};',
contentHtml:
'import React from "react";\n\nexport const App = () => {\n\n\treturn(\n\t\t<div>Hello</div>\n\t);\n}; highlighted',
createdAt: expect.any(Date),
description: 'Basic react component',
folderId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ describe('Test Update Snippet DTO', () => {
const dto = new UpdateSnippetDto({
content:
'import React from "react";\n\nexport const App = () => {\n\n\treturn(\n\t\t<div>Hello Updated</div>\n\t);\n};',
contentHighlighted:
'import React from "react";\n\nexport const App = () => {\n\n\treturn(\n\t\t<div>Hello Updated</div>\n\t);\n}; highlighted',
creatorId: userId,
description: 'Basic react component updated',
language: 'tsx',
Expand All @@ -34,6 +36,8 @@ describe('Test Update Snippet DTO', () => {
const expectedSnippet: Snippet = {
content:
'import React from "react";\n\nexport const App = () => {\n\n\treturn(\n\t\t<div>Hello Updated</div>\n\t);\n};',
contentHtml:
'import React from "react";\n\nexport const App = () => {\n\n\treturn(\n\t\t<div>Hello Updated</div>\n\t);\n}; highlighted',
createdAt: currentSnippet.createdAt,
description: 'Basic react component updated',
folderId: snippetToUpdate.folderId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ describe('Test Snippet service', () => {
// THEN
expect(expectedSnippet).toMatchObject<Snippet>({
content: createSnippetDto.toSnippet().content,
contentHtml: createSnippetDto.toSnippet().contentHtml,
createdAt: expect.any(Date),
description: createSnippetDto.toSnippet().description,
folderId: rootFolder.id,
Expand Down Expand Up @@ -64,7 +65,7 @@ describe('Test Snippet service', () => {
await deleteTestUsersById([user.id]);
});

it('should find all public snippets', async () => {
it('should retrieve all public snippets', async () => {
// GIVEN
const [user, rootFolder] = await createUserWithRootFolder();
const existingSnippets = await Promise.all([
Expand All @@ -77,10 +78,37 @@ describe('Test Snippet service', () => {
]);

// WHEN
const publicSnippets = await snippetService.findPublicSnippet();
const publicSnippets = await snippetService.findPublicSnippet({ itemPerPage: 10 });

// THEN
await expect(publicSnippets).toHaveLength(4);
await expect(publicSnippets.hasMore).toEqual(false);
await expect(publicSnippets.nextCursor).toEqual(null);
await expect(publicSnippets.items).toHaveLength(4);

await deleteTestSnippetsById(existingSnippets.map((snippet) => snippet.id));
await deleteTestFoldersById([rootFolder.id]);
await deleteTestUsersById([user.id]);
});

it('should retrieve a subset of public snippets', async () => {
// GIVEN
const [user, rootFolder] = await createUserWithRootFolder();
const existingSnippets = await Promise.all([
createTestSnippet({ folderId: rootFolder.id, userId: user.id, visibility: 'public' }),
createTestSnippet({ folderId: rootFolder.id, userId: user.id, visibility: 'private' }),
createTestSnippet({ folderId: rootFolder.id, userId: user.id, visibility: 'public' }),
createTestSnippet({ folderId: rootFolder.id, userId: user.id, visibility: 'private' }),
createTestSnippet({ folderId: rootFolder.id, userId: user.id, visibility: 'public' }),
createTestSnippet({ folderId: rootFolder.id, userId: user.id, visibility: 'public' }),
]);

// WHEN
const publicSnippets = await snippetService.findPublicSnippet({ itemPerPage: 3 });

// THEN
await expect(publicSnippets.hasMore).toEqual(true);
await expect(publicSnippets.nextCursor).toEqual(expect.any(String));
await expect(publicSnippets.items).toHaveLength(3);

await deleteTestSnippetsById(existingSnippets.map((snippet) => snippet.id));
await deleteTestFoldersById([rootFolder.id]);
Expand Down
5 changes: 4 additions & 1 deletion packages/domain/__tests__/setup/test-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,8 +153,11 @@ export const createTestSnippetDto = (
const languageIndex = randNumber({ max: languages.length - 1, min: 0 });
const themeIndex = randNumber({ max: themes.length - 1, min: 0 });

const snippetContent = randWord({ length: randNumber({ max: 30, min: 5 }) }).join('\n');

return new CreateSnippetDto({
content: randWord({ length: randNumber({ max: 30, min: 5 }) }).join('\n'),
content: snippetContent,
contentHighlighted: `${snippetContent} highlighted`,
description: randWord({ length: randNumber({ max: 20, min: 10 }) }).join(' '),
folderId: args?.folderId ?? generateTestId(),
language: languages[languageIndex],
Expand Down
4 changes: 2 additions & 2 deletions packages/domain/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
"build": "tsc --project tsconfig.prod.json",
"clean": "rm -rf .turbo dist",
"lint": "eslint --fix",
"db:test": "docker run -d --rm -e MYSQL_ROOT_PASSWORD=secret -e MYSQL_DATABASE=sharingan --name sharingandb -p 3313:3306 mysql:8.0",
"db:test:stop": "docker container kill sharingandb",
"db:test": "docker run -d --rm -e MYSQL_ROOT_PASSWORD=secret -e MYSQL_DATABASE=sharingan --name sharingandb -p 3313:3306 mysql:8.0.23",
"db:test:stop": "docker container kill sharingandb && docker container prune -f",
"db:test:migration": "npx prisma migrate dev --schema=../database/prisma/schema.test.prisma",
"test": "TEST_WITH_DB=true IS_LOCAL=false jest",
"test:unit": "jest",
Expand Down
2 changes: 2 additions & 0 deletions packages/domain/src/snippets/dtos/create-snippet-dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { Snippet, SnippetVisibility, dbId } from '@sharingan/database';

type Input = {
content: string;
contentHighlighted: string;
description: string | null;
folderId: string;
language: string;
Expand Down Expand Up @@ -30,6 +31,7 @@ export default class CreateSnippetDto {
toSnippet(): Snippet {
return {
content: this._input.content,
contentHtml: this._input.contentHighlighted,
createdAt: new Date(),
description: this._input.description,
folderId: this._input.folderId,
Expand Down
2 changes: 2 additions & 0 deletions packages/domain/src/snippets/dtos/update-snippet-dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { Snippet, SnippetVisibility } from '@sharingan/database';

type Input = {
content: string;
contentHighlighted: string;
creatorId: string;
description: string | null;
language: string;
Expand Down Expand Up @@ -31,6 +32,7 @@ export default class UpdateSnippetDto {
return {
...currentSnippet,
content: this._input.content,
contentHtml: this._input.contentHighlighted,
description: this._input.description,
language: this._input.language,
lineHighlight: this._input.lineHighlight,
Expand Down
1 change: 1 addition & 0 deletions packages/domain/src/snippets/snippet.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export default class SnippetService {
return dbClient.snippet.create({
data: {
content: input.content,
contentHtml: input.contentHtml,
description: input.description,
folderId: input.folderId,
id: input.id,
Expand Down