-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
220 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
export { postNote } from './note.ts'; | ||
export { addMedia, postNote } from './note.ts'; | ||
export { addBook, finishBook, getCurrentBooks } from './book.ts'; | ||
export { setCurrentTrack, setCurrentTrackFromSpotifyUrl } from './track.ts'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
import { assertEquals } from 'std/assert/mod.ts'; | ||
import { assertSpyCall, assertSpyCalls, spy } from 'std/testing/mock.ts'; | ||
import { createApp } from '../api/app.ts'; | ||
import { mock } from './_mock.ts'; | ||
import 'temporal-polyfill/global'; | ||
|
||
const BASE_URL = 'http://localhost:8000'; | ||
|
||
Deno.test('API /add-media creates if not exists ok', async () => { | ||
const { services } = mock(); | ||
|
||
services.fileHost.getFile = spy(() => Promise.resolve(null)); | ||
|
||
const router = createApp(services); | ||
const date = Temporal.ZonedDateTime.from('2024-03-07T08:27:35[Asia/Bangkok]'); | ||
const res = await router.run( | ||
new Request(new URL('/add-media', BASE_URL), { | ||
method: 'POST', | ||
headers: { | ||
Authorization: 'API-Token aaa', | ||
ContentType: 'application/json', | ||
}, | ||
body: JSON.stringify({ | ||
contents: 'Some movie I watched', | ||
date: date, | ||
tags: 'bar,baz', | ||
}), | ||
}), | ||
); | ||
|
||
assertEquals(res.status, 200); | ||
|
||
assertSpyCalls(services.fileHost.putFile, 1); | ||
assertSpyCall(services.fileHost.putFile, 0, { | ||
args: [ | ||
`---\ndate: '2024-03-07T08:27:35+07:00'\ntimezone: Asia/Bangkok\ntags:\n - bar\n - baz\n - recently\n---\n## Uncategorised\n\n- Some movie I watched\n\n`, | ||
'src/notes/_CURRENT.md', | ||
], | ||
}); | ||
}); | ||
|
||
Deno.test('API /add-media appends if exists ok', async () => { | ||
const { services } = mock(); | ||
|
||
services.fileHost.getFile = spy(() => Promise.resolve(`--- | ||
date: '2024-03-07T08:27:35+07:00' | ||
timezone: Asia/Bangkok | ||
tags: | ||
- bar | ||
- baz | ||
- recently | ||
--- | ||
## Movies | ||
- The Godfather | ||
## Uncategorised | ||
- A music track | ||
`)); | ||
|
||
const router = createApp(services); | ||
const date = Temporal.ZonedDateTime.from('2024-03-07T08:27:35[Asia/Bangkok]'); | ||
const res = await router.run( | ||
new Request(new URL('/add-media', BASE_URL), { | ||
method: 'POST', | ||
headers: { | ||
Authorization: 'API-Token aaa', | ||
ContentType: 'application/json', | ||
}, | ||
body: JSON.stringify({ | ||
contents: 'Some movie I watched', | ||
date: date, | ||
tags: 'bar,baz', | ||
}), | ||
}), | ||
); | ||
|
||
assertEquals(res.status, 200); | ||
|
||
assertSpyCalls(services.fileHost.putFile, 1); | ||
assertSpyCall(services.fileHost.putFile, 0, { | ||
args: [ | ||
`---\ndate: '2024-03-07T08:27:35+07:00'\ntimezone: Asia/Bangkok\ntags:\n - bar\n - baz\n - recently\n---\n## Movies\n\n- The Godfather\n\n## Uncategorised\n\n- A music track\n- Some movie I watched\n\n`, | ||
'src/notes/_CURRENT.md', | ||
], | ||
}); | ||
}); |