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(embed): handle snippet not found #53

Merged
merged 6 commits into from
Oct 17, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
chore(embed): setup tests
  • Loading branch information
tericcabrel committed Oct 12, 2022
commit 5913b9bbf15763ad401e4e436e601318acf93bb8
2 changes: 1 addition & 1 deletion packages/embed/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"ignorePatterns": ["dist", "build", "tsup.config.ts", "env.d.ts", "src/server/public"],
"ignorePatterns": ["dist", "build", "tsup.config.ts", "env.d.ts", "src/server/public", "jest.config.ts"],
"parserOptions": {
"ecmaVersion": 2021,
"sourceType": "module",
Expand Down
15 changes: 15 additions & 0 deletions packages/embed/jest.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import type { Config } from '@jest/types';

const config: Config.InitialOptions = {
roots: ['.'],
preset: 'ts-jest',
testMatch: ['**/?(*.)+(spec|test).[jt]s'],
testEnvironment: 'node',
clearMocks: true,
maxWorkers: 1,
snapshotFormat: {
printBasicPrototype: false,
},
};

export default config;
8 changes: 6 additions & 2 deletions packages/embed/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,26 @@
"scripts": {
"build:cdn": "tsup",
"build:cdn:watch": "tsup --watch",
"build:lib": "tsc",
"build:lib": "tsc --project tsconfig.prod.json",
"build": "yarn build:lib && yarn build:cdn",
"clean": "rm -rf .turbo dist build",
"dev": "nodemon --watch \"*.ts\" --exec \"ts-node\" ./src/server/index.ts",
"lint": "eslint src",
"preview": "serve ./src/server/static -l 7503",
"push": "cp package.publish.json build/package.json && cd build && npm publish --access=public"
"push": "cp package.publish.json build/package.json && cd build && npm publish --access=public",
"test": "jest"
},
"devDependencies": {
"@sharingan/database": "*",
"@types/express": "^4.17.13",
"@types/jest": "^29.1.2",
"@types/node": "^18.7.11",
"express": "^4.18.1",
"jest": "^29.1.2",
"nodemon": "^2.0.19",
"serve": "^14.0.1",
"shiki": "^0.11.1",
"ts-jest": "^29.0.3",
"ts-node": "^10.9.1",
"tsup": "^6.2.2",
"typescript": "^4.8.4"
Expand Down
34 changes: 34 additions & 0 deletions packages/embed/src/oembed/tests/generate-metadata.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { generateOembedMetadata } from '../index';

describe('Test Generate Oembed metadata', () => {
it('should generate Oembed metadata for a code snippet', () => {
// GIVEN
const snippet = { id: 'snippet_id', name: 'snippet-name.java' };
const SNIPPET_RENDERER_URL = 'https://embed.sharingan.dev';
const WEB_APP_URL = 'https://sharingan.dev';

// WHEN
const result = generateOembedMetadata({
snippet,
snippetRendererURL: SNIPPET_RENDERER_URL,
webAppURL: WEB_APP_URL,
});

// THEN
expect(result).toMatchInlineSnapshot(`
{
"height": 500,
"html": "<iframe width="750" height="500" src="https://embed.sharingan.dev/snippets/snippet_id" style="width:750px; height:500px; border:0; border-radius: 4px; overflow:hidden;" sandbox="allow-modals allow-forms allow-popups allow-scripts allow-same-origin"></iframe>",
"provider_name": "Sharingan",
"provider_url": "https://sharingan.dev",
"thumbnail_height": "720",
"thumbnail_url": "https://sharingan.dev/assets/og.png",
"thumbnail_width": "1280",
"title": "snippet-name.java",
"type": "rich",
"version": "1.0",
"width": 750,
}
`);
});
});
8 changes: 8 additions & 0 deletions packages/embed/tsconfig.prod.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"$schema": "https://json.schemastore.org/tsconfig",
"extends": "./tsconfig.json",
"exclude": [
"node_modules",
"./src/**/*.test.ts"
]
}
Loading