Skip to content

Commit

Permalink
add test for setCookie
Browse files Browse the repository at this point in the history
  • Loading branch information
Heyrows committed Aug 11, 2021
1 parent 2675fae commit 2340d22
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions packages/prismic-cli/test/prismic/communication.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,12 @@ describe('prismic/communication.ts', () => {
describe('new Prismic()', () => {
const fakeReadFail = sinon.fake.throws(fileNotFound)
const fakeWriteFileSync = sinon.fake.resolves(null)
const fakeWriteFileAsync = sinon.fake.resolves(null)

beforeEach(() => {
fakeWriteFileSync.resetHistory()
})

test
.stub(fs, 'readFileSync', fakeReadFail)
.stub(fs, 'writeFileSync', fakeWriteFileSync)
Expand Down Expand Up @@ -125,6 +131,27 @@ describe('prismic/communication.ts', () => {
expect(prismic.cookies).to.equal('')
expect(prismic.base).to.equal('https://prismic.io')
})

test
.stub(fs, 'readFileSync', fakeReadFail)
.stub(fs, 'writeFileSync', fakeWriteFileSync)
.stub(fs, 'writeFile', fakeWriteFileAsync)
.it('Prismic.setCookie should modify the config file from file system and set the internal value', async () => {
const prismic = new Prismic()
const fakeCookies = ['SESSION=session-token', 'prismic-auth=auth-token']
await prismic.setCookies(fakeCookies)

expect(fakeWriteFileAsync.getCall(0).args).to.deep.equal([
prismic.configPath,
JSON.stringify({
base: 'https://prismic.io',
cookies: fakeCookies.join('; '),
}, null, '\t'),
'utf-8',
])
expect(prismic.cookies).to.equal(fakeCookies.join('; '))
expect(prismic.base).to.equal('https://prismic.io')
})
})

describe('login', () => {
Expand Down

0 comments on commit 2340d22

Please sign in to comment.