|
| 1 | +package notionapi |
| 2 | + |
| 3 | +import ( |
| 4 | + "testing" |
| 5 | + "time" |
| 6 | +) |
| 7 | + |
| 8 | +func TestPdfBlockImplementsDownloadableFileBlock(t *testing.T) { |
| 9 | + // Test setup |
| 10 | + now := time.Now() |
| 11 | + pdfBlock := &PdfBlock{ |
| 12 | + Pdf: Pdf{ |
| 13 | + File: &FileObject{ |
| 14 | + URL: "https://example.com/file.pdf", |
| 15 | + ExpiryTime: &now, |
| 16 | + }, |
| 17 | + }, |
| 18 | + } |
| 19 | + |
| 20 | + // Test GetURL |
| 21 | + if url := pdfBlock.GetURL(); url != "https://example.com/file.pdf" { |
| 22 | + t.Errorf("Expected URL to be 'https://example.com/file.pdf', got %s", url) |
| 23 | + } |
| 24 | + |
| 25 | + // Test GetExpiryTime |
| 26 | + if expiry := pdfBlock.GetExpiryTime(); expiry != &now { |
| 27 | + t.Errorf("Expected expiry time to be %v, got %v", now, expiry) |
| 28 | + } |
| 29 | +} |
| 30 | + |
| 31 | +func TestFileBlockImplementsDownloadableFileBlock(t *testing.T) { |
| 32 | + // Test setup |
| 33 | + now := time.Now() |
| 34 | + fileBlock := &FileBlock{ |
| 35 | + File: BlockFile{ |
| 36 | + File: &FileObject{ |
| 37 | + URL: "https://example.com/file.txt", |
| 38 | + ExpiryTime: &now, |
| 39 | + }, |
| 40 | + }, |
| 41 | + } |
| 42 | + |
| 43 | + // Test GetURL |
| 44 | + if url := fileBlock.GetURL(); url != "https://example.com/file.txt" { |
| 45 | + t.Errorf("Expected URL to be 'https://example.com/file.txt', got %s", url) |
| 46 | + } |
| 47 | + |
| 48 | + // Test GetExpiryTime |
| 49 | + if expiry := fileBlock.GetExpiryTime(); expiry != &now { |
| 50 | + t.Errorf("Expected expiry time to be %v, got %v", now, expiry) |
| 51 | + } |
| 52 | +} |
| 53 | + |
| 54 | +func TestImageBlockImplementsDownloadableFileBlock(t *testing.T) { |
| 55 | + // Test setup |
| 56 | + now := time.Now() |
| 57 | + imageBlock := &ImageBlock{ |
| 58 | + Image: Image{ |
| 59 | + File: &FileObject{ |
| 60 | + URL: "https://example.com/image.jpg", |
| 61 | + ExpiryTime: &now, |
| 62 | + }, |
| 63 | + }, |
| 64 | + } |
| 65 | + |
| 66 | + // Test GetURL |
| 67 | + if url := imageBlock.GetURL(); url != "https://example.com/image.jpg" { |
| 68 | + t.Errorf("Expected URL to be 'https://example.com/image.jpg', got %s", url) |
| 69 | + } |
| 70 | + |
| 71 | + // Test GetExpiryTime |
| 72 | + if expiry := imageBlock.GetExpiryTime(); expiry != &now { |
| 73 | + t.Errorf("Expected expiry time to be %v, got %v", now, expiry) |
| 74 | + } |
| 75 | +} |
| 76 | + |
| 77 | +func TestExternalURLCases(t *testing.T) { |
| 78 | + // Test External URLs for each block type |
| 79 | + testCases := []struct { |
| 80 | + name string |
| 81 | + block DownloadableFileBlock |
| 82 | + expected string |
| 83 | + }{ |
| 84 | + { |
| 85 | + name: "PDF with external URL", |
| 86 | + block: &PdfBlock{ |
| 87 | + Pdf: Pdf{ |
| 88 | + External: &FileObject{ |
| 89 | + URL: "https://external.com/file.pdf", |
| 90 | + }, |
| 91 | + }, |
| 92 | + }, |
| 93 | + expected: "https://external.com/file.pdf", |
| 94 | + }, |
| 95 | + { |
| 96 | + name: "File with external URL", |
| 97 | + block: &FileBlock{ |
| 98 | + File: BlockFile{ |
| 99 | + External: &FileObject{ |
| 100 | + URL: "https://external.com/file.txt", |
| 101 | + }, |
| 102 | + }, |
| 103 | + }, |
| 104 | + expected: "https://external.com/file.txt", |
| 105 | + }, |
| 106 | + { |
| 107 | + name: "Image with external URL", |
| 108 | + block: &ImageBlock{ |
| 109 | + Image: Image{ |
| 110 | + External: &FileObject{ |
| 111 | + URL: "https://external.com/image.jpg", |
| 112 | + }, |
| 113 | + }, |
| 114 | + }, |
| 115 | + expected: "https://external.com/image.jpg", |
| 116 | + }, |
| 117 | + } |
| 118 | + |
| 119 | + for _, tc := range testCases { |
| 120 | + t.Run(tc.name, func(t *testing.T) { |
| 121 | + if url := tc.block.GetURL(); url != tc.expected { |
| 122 | + t.Errorf("Expected URL to be '%s', got '%s'", tc.expected, url) |
| 123 | + } |
| 124 | + }) |
| 125 | + } |
| 126 | +} |
0 commit comments