mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-17 18:12:04 +00:00
fix(Notion Node): Fix issue preventing some database page urls from working (#10070)
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import { formatBlocks } from '../shared/GenericFunctions';
|
||||
import { extractPageId, formatBlocks } from '../shared/GenericFunctions';
|
||||
|
||||
describe('Test NotionV2, formatBlocks', () => {
|
||||
it('should format to_do block', () => {
|
||||
@@ -31,3 +31,62 @@ describe('Test NotionV2, formatBlocks', () => {
|
||||
]);
|
||||
});
|
||||
});
|
||||
|
||||
describe('Test Notion', () => {
|
||||
const baseUrl = 'https://www.notion.so/fake-instance';
|
||||
const testIds = [
|
||||
'4eb10d5001254b7faaa831d72d9445aa', // Taken from Notion
|
||||
'fffb95d3060b80309027eb9c99605ec3', // Taken from user comment
|
||||
'a6356387779d4df485449a72a408f0d4', // Random v4 UUID
|
||||
'f4c1217e48f711ef94540242ac120002', // Random v1 UUID
|
||||
];
|
||||
describe('extractPageId From URL', () => {
|
||||
const extractPattern =
|
||||
'(?:https|http)://www.notion.so/(?:[a-z0-9-]{2,}/)?(?:[a-zA-Z0-9-]{1,}-)?([0-9a-f]{8}[0-9a-f]{4}[0-9a-f]{4}[0-9a-f]{4}[0-9a-f]{12})';
|
||||
// RLC does some Regex extraction before extractPageId is called
|
||||
const extractIdFromUrl = (url: string): string => {
|
||||
const match = url.match(extractPattern);
|
||||
return match ? match[1] : url;
|
||||
};
|
||||
|
||||
test('should return the part after "p="', () => {
|
||||
for (const testId of testIds) {
|
||||
const page = `${baseUrl}?p=${testId}`;
|
||||
const result = extractPageId(extractIdFromUrl(page));
|
||||
expect(result).toBe(testId);
|
||||
}
|
||||
});
|
||||
|
||||
test('should return the last part after splitting by "-" when URL contains multiple "-"', () => {
|
||||
for (const testId of testIds) {
|
||||
const page = `${baseUrl}/some-page-${testId}`;
|
||||
const result = extractPageId(extractIdFromUrl(page));
|
||||
expect(result).toBe(testId);
|
||||
}
|
||||
});
|
||||
|
||||
test('should return the last part after splitting by "-" when URL contains one "-"', () => {
|
||||
for (const testId of testIds) {
|
||||
const page = `${baseUrl}/1-${testId}`;
|
||||
const result = extractPageId(extractIdFromUrl(page));
|
||||
expect(result).toBe(testId);
|
||||
}
|
||||
});
|
||||
|
||||
test('should return just the id when there is an instance name', () => {
|
||||
for (const testId of testIds) {
|
||||
const page = `${baseUrl}/${testId}`;
|
||||
const result = extractPageId(extractIdFromUrl(page));
|
||||
expect(result).toBe(testId);
|
||||
}
|
||||
});
|
||||
|
||||
test('should return the id when there is no instance name', () => {
|
||||
for (const testId of testIds) {
|
||||
const page = `https://www.notion.so/${testId}`;
|
||||
const result = extractPageId(extractIdFromUrl(page));
|
||||
expect(result).toBe(testId);
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user