Skip to content

Commit

Permalink
Merge pull request #87 from darronz/credentials-header
Browse files Browse the repository at this point in the history
Allow configuration of credentials header
  • Loading branch information
richmolj authored Dec 2, 2020
2 parents 851a9c4 + ec19c32 commit c4e085a
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ export class SpraypaintBase {
static strictAttributes: boolean = false
static logger: ILogger = defaultLogger
static sync: boolean = false
static credentials: "same-origin" | "omit" | "include" | undefined
static clientApplication: string | null = null
static patchAsPost: boolean = false

Expand Down Expand Up @@ -756,6 +757,10 @@ export class SpraypaintBase {
} as any
}

if (this.credentials) {
options.credentials = this.credentials
}

if (this.clientApplication) {
options.headers["Client-Application"] = this.clientApplication
}
Expand Down
20 changes: 20 additions & 0 deletions test/unit/model.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1493,6 +1493,26 @@ describe("Model", () => {
})

describe("#fetchOptions", () => {
context("credentials is set", () => {
beforeEach(() => {
Author.credentials = "include"
})

afterEach(() => {
Author.credentials = "same-origin"
})

it("sets the credentials header", () => {
expect(<any>Author.fetchOptions().credentials).to.eq("include")
})
})

context("credentials is NOT set", () => {
it("sets the credentials header", () => {
expect(<any>Author.fetchOptions().credentials).to.eq("same-origin")
})
})

context("clientApplication is set", () => {
beforeEach(() => {
Author.clientApplication = "test-app"
Expand Down

0 comments on commit c4e085a

Please sign in to comment.