-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #80 from juni-b-queer/agent-save-session-data
feat: New IsNewPost validator to easily filter out the imported posts
- Loading branch information
Showing
3 changed files
with
82 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,7 @@ | |
/dist | ||
|
||
.env | ||
tests/temp | ||
|
||
.idea/ | ||
|
||
|
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,60 @@ | ||
import { | ||
CreateSkeetMessage, | ||
CreateSkeetMessageFactory, | ||
CreateSkeetRecord, | ||
CreateSkeetRecordFactory, | ||
HandlerAgent, | ||
IsNewPost, | ||
} from '../../../../src'; | ||
import { BskyAgent } from '@atproto/api'; | ||
import dotenv from 'dotenv'; | ||
import fs from 'fs'; | ||
|
||
const sessPath = './tests/temp/val/post/isNewPost'; | ||
dotenv.config(); | ||
process.env.SESSION_DATA_PATH = sessPath; | ||
|
||
describe('IsNewPost', () => { | ||
afterAll(() => { | ||
fs.rmSync(sessPath, { | ||
recursive: true, | ||
force: true, | ||
}); | ||
}); | ||
fs.mkdirSync(sessPath, { recursive: true }); | ||
const validator = IsNewPost.make(); | ||
const botDid = 'did:plc:bot'; | ||
const bskyAgent: BskyAgent = { | ||
session: { | ||
did: botDid, | ||
}, | ||
} as BskyAgent; | ||
const handlerAgent: HandlerAgent = new HandlerAgent( | ||
'name', | ||
'handle', | ||
'password', | ||
bskyAgent | ||
); | ||
|
||
test('handle returns true if message is created within the last 24 hours', async () => { | ||
const recentDate = new Date(); | ||
recentDate.setHours(recentDate.getHours() - 1); | ||
const message: CreateSkeetMessage = CreateSkeetMessageFactory.factory() | ||
.record({ | ||
createdAt: recentDate.toISOString(), | ||
} as CreateSkeetRecord) | ||
.create(); | ||
|
||
expect(await validator.handle(handlerAgent, message)).toBe(true); | ||
}); | ||
|
||
test('handle returns false if message is created more than 24 hours ago', async () => { | ||
const oldDate = new Date(); | ||
oldDate.setDate(oldDate.getDate() - 2); | ||
const message: CreateSkeetMessage = CreateSkeetMessageFactory.factory() | ||
.record({ createdAt: oldDate.toISOString() } as CreateSkeetRecord) | ||
.create(); | ||
|
||
expect(await validator.handle(handlerAgent, message)).toBe(false); | ||
}); | ||
}); |