Skip to content

Commit

Permalink
refactor: move test setup closer to describe call
Browse files Browse the repository at this point in the history
  • Loading branch information
alxndr committed Nov 22, 2024
1 parent 7981874 commit 218688b
Showing 1 changed file with 9 additions and 14 deletions.
23 changes: 9 additions & 14 deletions index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ describe('handlePayload', () => {
let payload
beforeEach(() => {
const data = {
show_id: 123
show_id: 0
}
payload = {
body: JSON.stringify(data)
Expand All @@ -108,7 +108,13 @@ describe('handlePayload', () => {
})
})
describe('with well-formed latest.json', () => {
// TODO move mockJson call here instead of more-deeply-nested
beforeEach(() => {
mockJson(/\bkglw\.net\b.+\blatest\.json$/, {data: [
{show_id: 789, songname: 'Couple Songs Ago'},
{show_id: 456, songname: 'Prior Song Title'},
{show_id: 123, songname: 'Newest Song'},
]})
})
describe('when prior post does NOT match latest song title', () => {
beforeEach(() => {
vi.mocked(Bluesky.prototype.getMostRecentPost).mockResolvedValue({post: {
Expand All @@ -119,9 +125,6 @@ describe('handlePayload', () => {
let mockRecentPost
beforeEach(() => {
mockRecentPost = vi.mocked(Bluesky.prototype.getMostRecentPost).mockResolvedValue({} as any)
mockJson(/\bkglw\.net\b.+\blatest\.json$/, {data: [
{show_id: 666, songname: 'Most Recent Song Name'},
]})
})
afterEach(() => {
mockRecentPost = null
Expand All @@ -136,16 +139,8 @@ describe('handlePayload', () => {
describe(`when payload's show_id matches fetched JSON's data[-1].show_id`, () => {
let mockedPost
beforeEach(() => {
vi.mocked(Bluesky.prototype.login).mockResolvedValue()
vi.mocked(Bluesky.prototype.getMostRecentPost).mockResolvedValue({post: {
record: {text: 'Prior Song Title'}
}} as any)
payload.body = JSON.stringify({show_id: 123})
mockedPost = vi.mocked(Bluesky.prototype.createNewPost).mockResolvedValue({} as any)
mockJson(/\bkglw\.net\b.+\blatest\.json$/, {data: [
{show_id: 789, songname: 'Couple Songs Ago'},
{show_id: 456, songname: 'Prior Song Title'},
{show_id: 123, songname: 'Newest Song'},
]})
})
afterEach(() => {
mockedPost = null
Expand Down

0 comments on commit 218688b

Please sign in to comment.